• Resolved laserjones

    (@laserjones)


    Hello,

    I found that when free shipping is offered (e.g. due to a certain minimum cart subtotal exceeded by the customer), the flat rate shipping option is still offered as well.

    I consider this a bug, as it does not make sense to offer both, and it confuses the customer. I suggest that this should be fixed in a future release.

    In an older post I found a code snippet for hiding all other shipping methods if free shipping is offered, but
    1) that post was several years old, and much has changed in WooCommerce since then (e.g. shipping zones), and
    2) I don’t want *all* shipping methods to be hidden, only flat rate shipping. Local pickup should still be offered.

    If anyone has a solution for me until this bug gets finally fixed, I would greatly appreciate it.

    Best regards,
    J?rg

    https://www.ads-software.com/plugins/woocommerce/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Plugin Contributor Mike Jolley

    (@mikejolley)

    Thread Starter laserjones

    (@laserjones)

    Thanks – that’s a point. But it would still be great to have an option in the backend to hide paid shipping if free shipping is enabled, because many people will want to offer free shipping *instead* of paid shipping under certain conditions.

    That code snippet apparently hides *all* other methods and doesn’t leave local pickup available. So unfortunately, it does not help me. Thanks anyway.

    Plugin Contributor Mike Jolley

    (@mikejolley)

    There are similar snippets in that file; the only change you’d need would be to use the correct 2.6 method ID to unset it, which may be something like flat_rate:1 where 1 is the instance ID. This is what changed in 2.6

    Thread Starter laserjones

    (@laserjones)

    I found a snippet for 2.6 that is supposed to do what I need. It’s the first one on this page: https://businessbloomer.com/woocommerce-hide-shipping-options-free-shipping-available/

    I added that to the functions.php of my child theme, but it has no effect. Maybe the instance IDs in that example do not match those in my shop? If so, how can I determine the correct IDs?

    Plugin Contributor Mike Jolley

    (@mikejolley)

    Edit the shipping rate and look in the address bar.

    Thread Starter laserjones

    (@laserjones)

    It still doesn’t work. Both the free shipping option and the flat rate I want to hide are assigned to shipping zone 1. So I used the following code:

    add_filter( 'woocommerce_package_rates', 'bbloomer_unset_shipping_when_free_is_available_in_zone', 10, 2 );
    
    function bbloomer_unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
    
        if ( isset( $rates['free_shipping:1'] ) ) {
        unset( $rates['flat_rate:1'] );
    }   
    
    return $rates;
    
    }

    But still flat rate shipping appears in addition to free shipping in zone 1. Any other ideas? (I did verify that the function is actually called – it is.)

    Thread Starter laserjones

    (@laserjones)

    Aaah, now it works. ?? The address bar at the top of my browser only showed the shipping zone ID (1 in this case), but the instance IDs differ from that and are only visible in the status bar at the bottom when the mouse hovers on the link to the respective shipping rate (which is opened as a pop-up, so the URL does not appear in the address bar). When I used the correct instance IDs, it worked. Thanks!

    This is quite complicated stuff for non-programmers, so I keep recommending to add this to the Woocommerce backend as an option, as it is surely needed by many users.

    Hi laserjones,
    Thanks for this, your snippet works perfectly for my Local Delivery Zone too.
    However, I also have a UK Delivery Zone and would like to also remove Standard Shipping from there aswell when Free Shipping is available. So how would I add multiple instance IDs to your code?

    Thread Starter laserjones

    (@laserjones)

    Hi Andy, I’m not a PHP programmer, but my guess would be that you can simply repeat the “if” statement (the “if” line plus the two lines that follow, i.e. including the closing “}”), just replacing the first instance ID with the other one.

    Hi,
    Thanks, I didn’t think repeating an if statement would work without using an elseif, but the following code does seem to be working for me:

    /* Removes Standard Flat Rate Shipping Option when Free Shipping is available */
    
    add_filter( 'woocommerce_package_rates', 'unset_shipping_when_free_is_available_in_zone', 10, 2 );
    
    function unset_shipping_when_free_is_available_in_zone( $rates, $package ) {
    
    // Removes Standard Flat Rate Shipping Option for Local Delivery Zone
        if ( isset( $rates['free_shipping:10'] ) ) {
        unset( $rates['flat_rate:13'] );
    }
    // Removes Standard Flat Rate Shipping Option for UK Delivery Zone
    	if ( isset( $rates['free_shipping:7'] ) ) {
        unset( $rates['flat_rate:1'] );
    }   
    
    return $rates;
    
    }

    Hopefully someone more experienced with PHP will be able to comment whether this is the best way of doing it and maybe it will help someone looking to achieve the same results.
    Please note: you will have to change the instance ID numbers for your particular Woocommerce Shipping Zone setup.

    Thread Starter laserjones

    (@laserjones)

    Glad that it worked. As far as I can see, “elseif” is not necessary here because the two “if” statements are independent of each other (rather than nested).

    Exactly what I was looking for. It worked perfectly. Thank you guys!!
    Mica.

    hi. where i paste this code ?
    Is possibile post it directly in my admin panel control, without open some file.php ?
    tnx

    /* Removes Standard Flat Rate Shipping Option when Free Shipping is available */

    add_filter( ‘woocommerce_package_rates’, ‘unset_shipping_when_free_is_available_in_zone’, 10, 2 );

    function unset_shipping_when_free_is_available_in_zone( $rates, $package ) {

    // Removes Standard Flat Rate Shipping Option for Local Delivery Zone
    if ( isset( $rates[‘free_shipping:10’] ) ) {
    unset( $rates[‘flat_rate:13’] );
    }
    // Removes Standard Flat Rate Shipping Option for UK Delivery Zone
    if ( isset( $rates[‘free_shipping:7’] ) ) {
    unset( $rates[‘flat_rate:1’] );
    }

    return $rates;

    }

    hi where u past the code ? tnx

    Thread Starter laserjones

    (@laserjones)

    You cannot simply post the code in the control panel, you must create a child theme for your WordPress theme and add the code to the functions.php file of the child theme. Please google for information on how to create a child theme, I cannot explain the entire process here. It’s not really difficult.

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘Flat rate shipping still offered when free shipping is available’ is closed to new replies.