• Resolved alvagram

    (@alvagram)


    Hi,

    I want to setup a pretty simple shipping rule for my local Shipping Zone :

    1. Flat rate shipping of €3 if order total is below 100€
    2. Free shipping if order total is 100€ and above

    So I have added and enabled 2 shipping methods in the zone : a Flat rate with cost €3, and a Free Shipping requiring a minimum order amount of €100.
    The problem is that during checkout the customer is presented with a list of 2 options for shipping (Flat Rate and Free Shipping). If the customer selects Free Shipping, Woocommerce proceeds to payment with free shipping even if the order is below €100.

    Ideally, no options at all should be shown during checkout : If order total is below €100 a shipping of €3 should be added. If order is €100 and above the “Free Shipping” should be displayed on the “Shipping” line.

    While trying to fix this, I tried the snippet shown at https://woocommerce.com/document/free-shipping/#hide-all-other-shipping-methods-when-free-shipping-is-available, however this resulted to showing only “free shipping” for all orders, even the ones below €100.

    Any ideas on how to fix this ?

    Thank you

    • This topic was modified 6 months, 2 weeks ago by alvagram.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Stef

    (@serafinnyc)

    Can you take a screenshot of your settings inside both options please? And place them here.

    Stef

    (@serafinnyc)

    For showing only Flat Rate when Free is not met you can use this hook

    function my_hide_shipping_when_free_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;
    }
    add_filter( 'woocommerce_package_rates', 'my_hide_shipping_when_free_is_available', 100 );
    Stef

    (@serafinnyc)

    I also forgot to mention there are more hooks here.

    Thread Starter alvagram

    (@alvagram)

    Stef,

    Thanks for your quick response. I had tried this code already but with no success. I still get both Flat Rate and Free Shipping as options on checkout. And even if order total is below the €100 threshold, woocommerce will allow the buyer to select the Free Shipping option.

    Here are my settings :

    And here what comes out at checkout :

    Free Shipping can be selected although the order total is below €100.

    Stef

    (@serafinnyc)

    Hello @alvagram are you clearing server and browser cache in between adding snippets? Make sure you are and make sure you never apply cache to a cart or checkout page.

    If after that still nothing then something is blocking this like an app or theme because I tested the above in 4 themes and it worked perfectly. You can test right here.

    Plugin Support Shameem R. a11n

    (@shameemreza)

    Hi @alvagram

    Could you edit the cost for the free shipping method and set it to 10000, as mentioned here? After doing so, test it again to see if it’s working correctly.

    However, we have some known report regarding this and our dev is aware of it:

    At the time being, we can’t give you an estimate for when the team will look into or fix the issue, as bug reports are prioritized based on a few criteria. Please subscribe to the GitHub issue if you’d like to receive updates.

    Looking forward to hearing from you soon.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘shipping : show only Flat Rate or Free Shipping on cart page’ is closed to new replies.