• Resolved Konstantinos

    (@stravojohn)


    im adding the following code and it’s working perfectly but when im adding more than two products it’s not working and it brings me all the possible shipping methods. Once i’m adding only one product again it brings the right shipping method.

    add_filter( 'woocommerce_package_rates', 'cssigniter_hide_other_methods_when_free_shipping_is_available', 100 );
    function cssigniter_hide_other_methods_when_free_shipping_is_available( $rates ) {
        $free = array();
        foreach ( $rates as $rate_id => $rate ) {
            if ( 'free_shipping' === $rate->method_id ) {
                $free[ $rate_id ] = $rate;
                break;
            }
        }
    
        return ! empty( $free ) ? $free : $rates;
    }

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @stravojohn,

    The issue you’re experiencing is likely because the code you’ve shared is set only to allow free shipping when there’s a single item in the cart. When you add more than one product, the code isn’t able to find a free_shipping method, hence it defaults to showing all available shipping methods.

    To enable free shipping for more than one product, you need to modify the code to check the total number of items in the cart, rather than just checking if there’s a single item.

    Additionally, you may try using the code snippet shared here: https://www.businessbloomer.com/woocommerce-hide-shipping-options-free-shipping-available/#php-snippet-2-unset-all-shipping-rates-in-all-zones-when-any-free-shipping-rate-is-available

    I hope this provides some clarity. Please let us know if you have any other questions!

    Thread Starter Konstantinos

    (@stravojohn)

    Hello I’ve added the code but it still isn’t working.

    I’ve done many combinations of adding products and moving to checkout and here is what I’ve found. When I’m adding a product with >50 euro which is my rule shipping method of free shipping is working fine.

    When I’m trying to add a second product and im forcing to checkout there are all the possible shipping methods. If I go back at shopping cart and add more quantity of second product and I move on at checkout it’s working fine and brings me up only free shipping.

    does it make sense?

    Plugin Support omarfpg a11n

    (@omarfpg)

    Hi @stravojohn,

    Can you please share your current settings for your shipping zones and shipping classes, as well as conditions for the free shipping?

    Additionally, can you please let us know if you’ve removed the previous code snippet in favor of the one provided by my colleague or if you’re using both?

    Finally, if you could share a System Status Report of your site that’d also help us learn more about it and we’ll be able to provide better support! You may find it by going to WooCommerce > Status > Get system report > Copy for support. You can paste it on https://gist.github.com/?and send the link here.

    Once we have more information, we’ll be able to assist you further.

    All the best,
    Omar

    Thread Starter Konstantinos

    (@stravojohn)

    Of course.

    1. Shipping zones -> Greece | Conditions of free shipping -> Minimum order 50 euro | I haven’t add any shipping class
    2. I have removed the previous code snippet
    3. https://gist.github.com/kstravogiannis/ac6af1342a7cca02b478470605ae6ddf
    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @stravojohn,

    When I’m trying to add a second product and im forcing to checkout there are all the possible shipping methods. If I go back at shopping cart and add more quantity of second product and I move on at checkout it’s working fine and brings me up only free shipping.

    I tried replicating the issue on my testing site by following the exact steps, but everything seems to work as expected.

    I used the code snippet shared here to hide all other shipping methods once the free one is available.

    However, let’s dive into troubleshooting this issue further. Start by increasing your PHP Post Max Size from 128 MB to a hefty 2 GB. Next, boost your PHP Time Limit from a mere 30 to a whopping 1200.

    After you’ve made those adjustments, head over to WooCommerce → Status → Tools, and do the following:

    • WooCommerce transients – Clear
    • Expired transients – Clear
    • Clear template cache – Clear
    • Capabilities – Reset Capabilities
    • Clear customer sessions -Clear
    • Product lookup tables – Regenerate
    • Regenerate the product attributes lookup table – Regenerate
    • Clear site and server cache.

    Next, please clear your browser cache and then test again.

    If this makes no difference, run a conflict test to identify the cause of the issue. More info: https://woo.com/document/how-to-test-for-conflicts/

    Let us know how that goes for you.

    Plugin Support omarfpg a11n

    (@omarfpg)

    Hi there ?? ,

    We haven’t heard from you in a while; this is to check if you’ve been able to proceed with the troubleshooting steps provided before and if you still need help.

    Thanks!
    -OP

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Woocommerce – Hide other shipping methods if free shipping is available not work’ is closed to new replies.