WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart

This is a very cool snippet that many of you should use to increase your average order value. Ecommerce customers who are near the “free shipping” threshold will try to add more products to cart in order to qualify for free shipping. It’s pure psychology.

Here’s how we show a simple message on the WooCommerce Cart page. Enjoy!

WooCommerce: get free shipping if you add "x" money
WooCommerce: get free shipping if you add “x” money

PHP Snippet: add notice to show remaining amount to reach free shipping threshold @ WooCommerce Cart

/**
 * @snippet       Notice with $$$ remaining to Free Shipping @ WooCommerce Cart
 * @how-to        Watch tutorial @ https://businessbloomer.com/?p=19055
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.6.2
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */

add_action( 'woocommerce_before_cart', 'bbloomer_free_shipping_cart_notice' );
 
function bbloomer_free_shipping_cart_notice() {
 
$min_amount = 50; //change this to your free shipping threshold
  
$current = WC()->cart->subtotal;
 
if ( $current < $min_amount ) {
   $added_text = esc_html__('Get free shipping if you order ', 'woocommerce' ) . wc_price( $min_amount - $current ) . esc_html__(' more!', 'woocommerce' );
   $return_to = apply_filters( 'woocommerce_continue_shopping_redirect', wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( 'shop' ) );
   $notice = sprintf( '<a href="%s" class="button wc-forward">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue Shopping', 'woocommerce' ), $added_text );
   wc_print_notice( $notice, 'notice' );
}
 
}

Where to add this code?

You can place PHP snippets at the bottom of your child theme functions.php file (before "?>" if you have it). CSS, on the other hand, goes in your child theme style.css file. Make sure you know what you are doing when editing such delicate files - if you need more guidance, please take a look at my free WooCommerce Customization video tutorial.

Does this snippet still work?

Please let me know in the comments if everything worked as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting on PHP 7.

If you think this code saved you time & money, please join other Business Bloomer supporters and avail of 365 days of WooCommerce benefits. Thank you in advance :)

Need Help with WooCommerce?

Check out these free videos, tutorials and tips!

  • how-to-edit-woocommerce-with-php-snippets
  • woocommerce-hooks-add_action-list-visual
  • woocommerce-customize-single-product-page-PHP
  • woocommerce-customize-shop-page-PHP
  • woocommerce-advanced-customization
  • how-to-edit-woocommerce-cart
  • woocommerce-customize-checkout-page-PHP
  • woocommerce-email-customization
  • woocommerce-conditional-logic

Rodolfo Melogli

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as a WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza.

174 thoughts on “WooCommerce: “You Only Need $$$ to Get Free Shipping!” @ Cart

  1. How can I show it based on the value entered in the admin panel, not the minimum value?

    Shipping Zone 1 = GERMANY – MฤฐN 25
    Shipping Zone 2 = TURKEY – MฤฐN 50
    Shipping Zone 3 = ENGLAND – MฤฐN 30

    When Germany is selected 25, England is selected 30.

    1. Hi Gurkan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

  2. Hi,

    I have added the code to the php file but i can’t find any css to add on this page, could you post it?

    1. Hey Howard, thanks for your comment – there is no CSS to go with this PHP snippet, so you’re good to go ๐Ÿ™‚

  3. Is there a way to turn this off if a shipping class is present in cart?

    1. Hey Connor, thanks for your comment! I suggest you take a look at “conditional logic”: https://businessbloomer.com/conditional-logic-woocommerce-tutorial/ and https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/. Let me know ๐Ÿ™‚

  4. Hello!

    Is it possible to display this message on the product page and replace the message when the item was added to the cart : “The product was succesfully added to your cart ” ?

    If yes could you provide me little instructions. Or if it is more difficult please e-mail me the price for it to complete the task.

    Thanks!

    1. Hello Ats, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  5. Hi Rodolfo

    Is there a way to display a Message once the minimum amount has been reached?
    “Congratulations! Your order qualifies for Free Shipping”

    Thanks for your help.

    1. Hello Miguel, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  6. Hello Rodolfo, great snippet. I have a problem, I set free shipping at 29 euros and everything works fine. But I also have product kits that would require free shipping even under 29 euros. I have assigned to these kits a shipping class and I use a plug-in that assigns free shipping. The problem is that your snippet is based on the amount of the cart and continues to say that you miss a few euros to reach free shipping. Is it possible to make the snippet work also based on a shipping class regardless of the amount shown on the cart?

    1. Marco, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R

  7. Thank you for your great snippet. I am new to this and love your references.
    Everything is working for me except that it only seems to take in count the first minimum Order amount of the first Shipping Zone (25.-).

    Shipping Zone 1 = CHF 25.-
    Shipping Zone 2 = CHF 29.-
    Shipping Zone 3 = CHF 30.-

    What am I doing wrong? Is somebody else having this problem?

    1. Hey Samuel, thanks for your comment! This snippet gets the cheapest free shipping threshold:

      $min_amount = min($min_amounts);
      

      …so the coding would need to be customized in case you wanted to display a conditional message based on the current shipping zone. Hope this helps!

  8. this snippet in the last woo version include ?

    1. Yes, works on 3.4.2 ๐Ÿ™‚

  9. Hi Rodolfo,

    Thank you a lot for sharing this. The version 2.6+ had 2 bugs that are fixed here:

    
    function bbloomer_free_shipping_cart_notice_zones_static() {
     
    // Define min_amount
     
    $min_amount = 50;
     
    // Get Cart Subtotal inc. Tax excl. Shipping
     
    $current = WC()-&gt;cart-&gt;subtotal;
     
    // If Subtotal &lt; Min Amount Echo Notice
    // and add &quot;Continue Shopping&quot; button
     
    if ( $current &lt; $min_amount ) {
    $added_text = esc_html__(&#039;Get free shipping if you order &#039;, &#039;woocommerce&#039; ) . wc_price( $min_amount - $current ) . esc_html__(&#039; more!&#039;, &#039;woocommerce&#039; );
    $return_to = apply_filters( &#039;woocommerce_continue_shopping_redirect&#039;, wc_get_raw_referer() ? wp_validate_redirect( wc_get_raw_referer(), false ) : wc_get_page_permalink( &#039;shop&#039; ) );
    $notice = sprintf( &#039;<a href="%s" rel="nofollow">%s</a> %s', esc_url( $return_to ), esc_html__( 'Continue Shopping', 'woocommerce' ), $added_text );
    wc_print_notice( $notice, 'notice' );
    }
     
    }
    
    

    (What I did: removed on “}” that caused an error and replaced wc_price( $threshold by wc_price( $min_amount)

    Do you know why the cart notice is not shown on mobile?

    Best regards,
    Ricardo

    1. Thanks a million Ricardo ๐Ÿ™‚ Re: cart notice, it could be a CSS problem?

  10. Great idea but it does not work when updating quantities on the actual product page.

    It remains static to the initial page load which defeats the purpose a bit for a user as they will want to see gradually how much more they have to buy as they tweak quantities.

    Personally not sure the functionality of the WC cart exists to manage that though.

    1. Hey Jimbo, thanks so much for your comment! This snippet works on the Cart page, so not sure what happens on the product page ๐Ÿ™‚ Try disabling the Ajax add to cart maybe?

  11. Hi Rodolfo. This is a great snippet and works well (I mean the WooCommerce 3.0.5 tested version). The only bug I found is about the case where I add to cart a cross sell product in cart page. In this case the wc_price( $min_amount – $current ) remain the same and it is not updated until the page is refreshed. How to fix the bug? Thanks for your works

    1. Fabrizio, thanks for your comment! Without touching code, the fastest fix would be to disable the Ajax add to cart from the WooCommerce settings and force a page refresh ๐Ÿ™‚

    2. Thanks Rodolfo…And…touching the code instead? ๐Ÿ™‚

    3. Hey Fabrizio, yes that’s possible of course but it’s custom work and cannot help here via the blog comments ๐Ÿ™‚

  12. Hi,
    I want to use a free shipping minimum order of 8.10, which is three products at 2.70 – so I am using this:

    $maximum = 8.10;
    	$current = WC()-&gt;cart-&gt;subtotal;
    	if ($current &lt; $maximum)
    		{
    		echo &#039;You will get free shipping if you spend ยฃ' . ($maximum - $current) . '.00 more!';
    		}
    

    And it works, except that in the cart page, if the customer has one product in the basket, the message is there but the figures read strangely – e.g. You will get free shipping if you spend ยฃ5.4.00 more!

    And I don’t know what to change to make it present OK.

    1. Hey David, can you test again with integer numbers only (8 and not 8.10)?

  13. Hi Rodolfo,
    Thank you very match for awesome snippet. But I have little problem.
    After pushing button ” back to the shop” I need redirect the visitor to root of shop page, not to the last position from which the client came to the cart page. will you please help me? thnkx

    1. Hello Peter, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  14. Is it possible to display this on a product page too? BTW very nice customization and the feedback from the community is great!

    1. Jonathan, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding and nice words! ~R

  15. Hi Rodolfo,

    I love your snipets thanks a lot.
    I have problem with this one. I show the notification on 2 places on the cart page: 1 is “woocommerce_before_cart”, 2 is “woocommerce_proceed_to_checkout, 15” so above the button. Everything is showing up on the right place, the amounts are good. But: when I change quantity of a product and the cart refresshing the two notification “jumping” to the “woocommerce_before_cart_table” place. When I refresh the page itself everything is OK again. Do you have any idea what can coze this?

    1. Hey Brigitta, thanks so much for your comment! If you only enable the default “woocommerce_before_cart” notification, do you get this error?

    2. Hi,
      you mean the “cart is updated” message? That message is also on the โ€œwoocommerce_before_cart_tableโ€ place.

    3. Sorry – didn’t explain well. If you use my exact snippet, do you still get the error?

    4. yes. I just disabled the snipet, and tested. I have the same problem with that.
      WooCommerce version: 3.2.0
      WP version: 4.8.3

    5. Hi,

      Yep, I have the same problem with the original too.

    6. Ok Brigitta, I tested the snippet and I see no error on my end. Maybe your theme (or another plugin) is messing/conflicting with my snippet?

      To troubleshoot, go to WP Dashboard > WooCommerce > System Status: what errors do you see in red font?

      Also, take a look at this tutorial to see how to troubleshoot: https://businessbloomer.com/woocommerce-troubleshooting-mistakes-to-avoid/

      Finally, can you try switching temporarily to “Twentyseventeen” or “Storefront” theme and let me know if it works?

      Hope this helps!

      R

    7. Hi Rodolfo,

      I watched the troubleshooting video, also a good one, congrats. I am learning a lot from you, many thanks!!
      I switched to โ€œTwentyseventeenโ€ : there I even did not get the notice.
      I disabled all my plugin except original woocommerce: the problem still there, the strange is that, if I comment out the snipet, the original “cart updated” message is also on the wrong place…
      System Status errors: – there are 6 plugins with: Not tested with the active version of WooCommerce
      – at Theme: 2 files: affinity/woocommerce/content-product.php verziรณ 2.6.1 old. new verziรณ: 3.0.0,
      affinity/woocommerce/global/quantity-input.php verziรณ 2.5.0 old. new verziรณ: 3.2.0.

      I tested the sinppet on another wp site with own theme, I copied there the cart.php coz I made a little modification on it and it is working perfectly.

    8. Ok, good to know – thank you ๐Ÿ™‚

  16. Thanks for this Rodolfo.
    Does this allow me to apply the message to only the shipping zones that have free shipping? I only offer free shipping on domestic orders; the rest do not have free shipping. I don’t want this message to appear on orders that are not domestic.

    1. Tamara, thanks so much for your comment! No, this basic shipping doesn’t check what the currently selected/located shipping zone is before outputting the notice – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  17. Hi Rodolfo
    Cool snippet ๐Ÿ˜‰
    Just wondering if you could provide me with a pointer please.
    In my woo setup I use advanced free shipping, 2 woo zones and 3 custom zones, and shipping by user role.
    Using your static version the snippet works great and displays accordingly.
    I am struggling to get the min amount for the specific method.
    I’ve been staring at this for two days now and could do with a direction to head in.
    Do I get the selected method first then try to get the min amount for that method, or do I get all methods and itterate through them to get min amount?
    And then… if is logged in conditional to retrieve the appropriate role rates.
    Maybe I am making this more difficult than it should be?
    Cheers

    1. Hey Andy, thanks so much for your comment! Yes, this is possible for sure and the code must be changed accordingly – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  18. Hi there,

    Sorry for the comment, I’m not an expert
    I added the sniped (dinamic first and then tried with the static) to the functions on my child theme. The first one didn’t show anything and the second one broke the site (error 500).

    Any idea what could it be or what I’m doing wrong?

    Thanks

    1. Monica, thanks for your comment! What error did you get (enable WP_DEBUG and you will get a description of the error)?

  19. Hello,
    is there a way i change the style text for “Get free shipping if you order ….” like text color or text size ?

    Thank you

    1. Albert, thanks for your comment! Yes, of course, you will need custom CSS for that. Sorry but I can’t help with custom work via the blog comments – thanks for your understanding!

  20. Hi,

    Great articld, may ฤฑ ask you something about it ?
    ฤฐs there any way to setting minimum order amount for different zones ?
    For example
    Minimum order amount should be 100 usd for zone code 34234 and it should be 50 usd for 41234

    ฤฑ am looking for it since couple weeks

    Thanks in Advance

    1. Chad, thanks for your comment! Each shipping zone has its own Free Shipping method; each Free Shipping method has its own threshold. If you do things right in the settings, this snippet will automatically know the current zone threshold. R

  21. hello sir,

    I just wanted to know if this works as well if the cart has shipping fee of say $10, then when a customer reached $250, the cart will then say FREE shipping, else the shipping fee of $10 will apply. I really appreciate your help

    1. Hey Zevi, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

  22. hi Sir,

    We would like to use this snippet.

    Unfortunately, every example does not have the correct ‘Sum’ of the prices.

    Maybe it is because of WC 3.0.8?
    Which snippet do we need to use for this version?

    Thanks in advance

    1. Hey Kuul, thanks for your comment! This snippet is compatible with Woo 3.0 and above, so I’d be surprised if that’s the issue. Probably the sums are not correct as you have taxes/shipping/fees etc., so it will need to be customized to your specific settings. Sorry but I can’t help here in the blog comments for free ๐Ÿ™‚

    2. Hey Kuul – You should just be able to change to be a different class that’s being used elsewhere in your theme and which doesn’t have the fancy flash in and out attributes.

  23. This is awesome, thanks. Any ideas on how I might add this info to the page itself (rather than wrap it in a notice)? My theme has rewritten the standard woo notice with custom flashing javascript notices that flash in and out, and reformats this message in a strange way ~ I’d love to just have this notice above the cart info, for example.

    1. Hey Mandm, thanks so much for your comment! Yes, this is possible – but unfortunately this is custom work and I cannot provide a complementary solution here on the blog. Thanks a lot for your understanding! ~R

  24. Hi Rodolfo,
    I added the code into my functions.php of my child theme but receive this error:

    Notice: Undefined variable: min_amounts in….child/functions.php on line 79

    Line 79 has this code on it – if ( is_array($min_amounts) ) {

    Where do I need to define the min amount?

    1. Hey Brett, thanks for your comment! Uhm, silly question I know, but do you have any “Free Shipping” methods with a “minimum order amount”?

    2. Sure do Rodolfo, free shipping on orders over $500.

    3. ๐Ÿ™‚

      And to what zone is that linked to?

    4. I’ve named the zone “Australia Wide”

      And the zone region is “Australia”

    5. Gotcha ๐Ÿ™‚ And I guess under WooCommerce > Settings you have “Geolocate” as the customer’s default address?

    6. Yes, that’s correct.

    7. Yes, I see. I’m testing it and if your geolocation is not the same as the zone with free shipping it doesn’t get the minimum amount ๐Ÿ™ I’ll see what I can do!

    8. Cool – I think I fixed it now. I rewrote the whole function and found a few bugs as well, so delete previous and copy the new one ๐Ÿ™‚ Let me know!

    9. GREAT!
      Thanks Rodolfo, works like a charm.

  25. Hello Rodolfo,
    I tried this code locally, but after reloading the page the message disappears. Why is this happening?

    1. Hey Aleksandar, thanks for your comment! I spent some time revising, retesting and correcting this snippet, now it should work – let me know ๐Ÿ™‚

  26. Hi, I trid to use this code, so I put it to functions.php of my chield theme. But there is no text/alert that I have to add more things for free shipping, It simply just dont work. I have the latest WP installed. What to do?

    1. Hey Vv, thanks for your comment! Can you try with the “Static” snippet I just added to the blog and then let me know?

  27. Thank you so much for this code & tutorial.

    How would I set it up to NOT INCLUDE TAX in the calculation? If my free shipping starts at $30 and I have $14 in the cart, I would like it to say I only need $16 more to get free shipping.

    I’m also having trouble with CSS to make the button “continue shopping” … I can probably figure it out eventually, but if you have your CSS for the bar and button available, that would be wonderful if you could share it.

    Thanks!

    1. Thanks for your comment Bob! Try using get_total_ex_tax() instead of subtotal (https://docs.woocommerce.com/wc-apidocs/class-WC_Cart.html). Let me know!

    2. Thanks for quick reply! (BTW – just signed up as a Supporter)…

      I don’t know if I used your code correctly, but now it returns “0”. Below is how I used the above code. (To keep it simple, I set minimum amount to $30.)

      // Set Min Amount
      $min_amount = 30;

      // Get Cart Subtotal inc. Tax excl. Shipping
      $current = WC()->cart->get_total_ex_tax();

    3. Uhm, weird. Maybe:

      WC()->cart->get_cart_total();

    4. Nope, didn’t work. Still returns “0”.

      I may give up for now and just have bar say, “Free Shipping if you order $30 or more.” and forget trying to calculate $30 – [subtotal without tax] = amount needed to purchase to get free shipping.

      Thanks for trying.

  28. Hi, nice feature and easy to implement but i have a question :

    Is there any change to make it permanent when u go to cart ?
    Or i have a template issue, because i only see it when i update cart…

    And mini cart seems won’t be able to display this messagen we talk about widget from woocommerce ?

    Regards

    1. Hey LeSScro, thanks for your comment! What do you mean by “permanent”? Let me know!

  29. Hello,
    thanks for this great tip! I have an issue.
    If i navigate from checkout page to the cart page, then the message shows correctly.
    If i navigate from another page to cart page, the message doesn’t appear. It seems that shipping methods are not loaded.
    I run Woocommerce 2.6.11 on WordPress 4.7.
    Thanks for your support!

    1. Hey Tiz thanks for your comment! I believe this snippet only works when the “system” knows the shipping zone (and as long as that shipping zone has a free shipping method). If not, no message shows I believe.

      Question – do you have just one free shipping method? In this case we can avoid to “get” the shipping zone and just hardcode the – for example = $150 into the function. Not sure if this makes sense?

  30. Hey Rodolfo! Excellent code. Exactly what I was looking for and didn’t have to buy a bulky plugin.

    2 questions to help me finish it off:

    1. When I change currency, the figures are calculated from 100. I don’t have this number hardcoded. I use free shipping at $100 AUD. But how can it change when the currency selection is made? It needs to be calculated from the currency equivalent of $100 AUD, not just 100.
    2. Can you suggest some more hooks to add the message:
    A. Directly below the “Proceed to Cart” button
    B. Top of the Checkout page
    C. Bottom of Checkout page
    D. Directly below the “Proceed to Paypal” button on the checkout page.

    Thanks again! I’d be happy to buy you a beer or coffee. Let me know where I can donate!
    Rob

    1. Hey Rob thanks for your comment and further message! As I said, this snippet doesn’t work with multicurrency, and will need an edit also based on the currency switcher plugin you use. In regard to the second question, I suggest to take a look at the available hooks on the cart (https://businessbloomer.com/woocommerce-visual-hook-guide-cart-page/) and checkout page (https://businessbloomer.com/woocommerce-visual-hook-guide-checkout-page/) to have an idea of where you can accomplish that. Hope this helps!

  31. Is it possible to make this line:

    if ( $current < $min_amount ) {
    echo 'Continue ShoppingGet free shipping if you order ‘ . wc_price( $min_amount – $current ) . ‘ more!’;
    }

    WPML ready? I’ve tried with _e(‘text’,’domaintext’) but it doesn’t work.

    1. Hey Duke, thanks so much for your comment! Yes, of course it is, I don’t see why it shouldn’t work – just take a look at how WPML suggests to echo strings and you’ll probably figure it out. Something along the lines of (untested):

      [php]
      echo ‘‘ . _e(‘Continue Shopping’,’woocommerce’) . ‘‘ . ‘Get free shipping if you order ‘ . wc_price( $min_amount โ€“ $current ) . ‘ more!’;
      [./php]

  32. […] Dziaล‚a dla Woo w wersji 2.6, oryginalne ลบrรณdล‚o rozwiฤ…zania oraz wersja dla WooCommerce 2.5 dostฤ™pne TU. […]

  33. HI Rodolfo

    I have used your snippet and have been very glad for it. Thank yo so much.
    I have one questions regarding this – before we set this to 500 as a minimum buy to get free shipping – works great – but know we set this to 300 – but it still keeps saying 500 for free shipping.

    I have triple checked everything in the shipping settings and for the plugin we are using to show drop points for a package, it gives the free shipping at 300 as it should, but the snippet still tells that you need 200 more to get free shipping. I think it is something from the old shipping settings, that the snippet is taking the info from. Is there a way that I can adjust the amount inside the snippet? just tell the snippet to set it to 300?

    Best regards

    Michael

    1. Michael, thanks for your comment! Yes, you can just tell the snippet to use ‘300’ instead of reading it from the settings.

      Substitute this:

      // Get Min Amount from Woo Settings
      $free_shipping_settings = get_option( 'woocommerce_free_shipping_settings' );
      $min_amount = $free_shipping_settings['min_amount']; 
      

      With this:

      // Set Min Amount 
      $min_amount = 300; 
      

      Let me know if this works ๐Ÿ™‚

    2. Hi Rodolfo

      Thank you very much – It works like a charme ๐Ÿ™‚

      But I just set it in the mini cart/widget cart

      Where do I put this in for the cart page? I dont see:

      // Get Min Amount from Woo Settings
      $free_shipping_settings = get_option( 'woocommerce_free_shipping_settings' );
      $min_amount = $free_shipping_settings['min_amount']; 
      

      Anywhere in the snippet?

      Should I delete all of this:

      global $woocommerce;
      $shipping_methods = $woocommerce-&gt;shipping-&gt;get_shipping_methods();
       
      // Loop through the array to find min_amount value/s
       
      foreach($shipping_methods as $key =&gt; $value) {
          if ( $shipping_methods[$key]-&gt;min_amount &gt; 0 ) {
            $min_amounts[$key] = $shipping_methods[$key]-&gt;min_amount;
          }
      }
       
      if ( is_array($min_amounts) ) {
       
      // Find lowest min_amount
       
      $min_amount = min($min_amounts);
      

      With this:

      // Set Min Amount 
      $min_amount = 300; 
      

      Again thank you so much – I am following you for upcoming events/snippets ๐Ÿ™‚

      best regards

      Michael

      Ps. Thank you for your quick response.

    3. Hey Michael, uhm, yes, sorry I was looking at the wrong snippet! Yes, you’re 100% correct. Let me know if it works ๐Ÿ™‚

    4. Hi Rodolfo

      Unfortunately it do not work – it do not show anything at all ๐Ÿ™

      I delete what mentioned in my other message and insert as you have shown me, but nothing happens.

      Could you try man setup a finished snippet, the way it should look, so I dont delete to much of it?

      Thank you again.

    5. Sure thing:

      
      function bbloomer_free_shipping_cart_notice_zones_new() {
      
      $min_amount = 300;
      
      $current = WC()->cart->subtotal;
      
      if ( $current < $min_amount ) {
      echo '<div class="woocommerce-message"><a href="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . '" class="button wc-forward">Continue Shopping</a>Get free shipping if you order ' . wc_price( $min_amount - $current ) . ' more!</div>';
      }
      
      }
      
      add_action( 'woocommerce_before_cart', 'bbloomer_free_shipping_cart_notice_zones_new' );
      
      
    6. I cant thank you enough Rodolfo – Works like a charm ๐Ÿ™‚

      best regards

      Michael

  34. Maybe i found some kind of bug:
    your code works great but if in the cart page you hit refresh or f5 the page reload and the value of remaining amount for free shipping “mysteriously” increase (in my case the total for free shipping mysteriously become 154โ‚ฌ).
    If you exceed the minimum of order for free shipping or empty the cart then all value back to normal.
    I tested on a site the 2.6+ version and it always occurs.
    It’s a real bug or my mistake?
    can you verify?
    Thanks a lot
    PS: sorry for my english i’m italian (maybe you too?)

    1. Ok, thank you Andrea – and your English is perfect (yes, I’m Italian). I will do some testing and then if necessary post a revised snippet ๐Ÿ™‚

  35. This doesn’t show until I change the quantity of products in the cart and then update, when I refresh the page it disappear again.

    If I also clear transients and refresh the page it shows, after the second refresh it disappear again.

    Any ideas?

    1. Sam, thanks for your feedback! Uhm, I understand the “echo” part is not ideal, I should have used the wc_notice function instead. Could you possibly double check by disabling ALL plugins but WooCommerce and switching theme temporarily to 2016, and let me know if it gives you the same error? Cheers ๐Ÿ™‚

    2. Hello Rodolfo,

      I got the same error that the man above me. I need to refresh it or go to checkout and back to view cart so it could appear.

      Any fix is more than welcome, and yes, I could prove you WP-admin details to test ๐Ÿ™‚

      Thank you so much!

    3. Drake, I tested this on my site and I don’t need to refresh anything to make it appear: http://screencast.com/t/ThdgfpMJEy

      Sure that you have the correct shipping settings? Sure, feel free to send me your login (privately) and I’ll take a look.

    4. Sam, I retested this on my site and I don’t need to refresh anything to make it appear: http://screencast.com/t/ThdgfpMJEy

      Sure that you have the correct shipping settings? Can you send me a screenshot/screencast with those?

    5. Hello Rodolfo,

      I had the same issue. The legend only appeared when I added a product to the cart and then disappeared after page reload. I did some experimentation. At some point, I activated the “Enable Shipping Debug Mode to show matching shipping zones and to bypass shipping rate cache” option at “WooCommerce/System Status/Tools” and now the legend always appears normally.

      Unfortunately, an additional unwanted legend appears which shows the shipping zone. I have managed to remove this additional legend. However, I wonder if activating the “Enable Shipping Debug Mode to show matching shipping zones and to bypass shipping rate cache” option is a good thing on the long run.

    6. Hey, thanks for your comment ๐Ÿ™‚ No, the shipping debug is not a good idea. I’ll do some tests and in case release a new update. Thanks for your patience ๐Ÿ™‚

  36. Hello Rodolfo

    Is there a way to hide the info if the minimum amount is reached?

    1. Michael, thanks for your comment! Actually, the line:

      if ( $current < $min_amount ) {
      

      …already does what you’re asking: unless the total is lower than the minimum, the notice will not be displayed. Unless you’ve tested this and are getting a different behavior? Let me know ๐Ÿ™‚

    2. Thank you it works now. I had a little bug in my script.

    3. Excellent! Thank you ๐Ÿ™‚

  37. Thanks for so great code snippet! Is it possible to add one more condition according to item quantity? For example, a customer can reach either amount or quantity to get free shipping. Thanks again!

    1. Hey Amos, thanks for your comment and great feedback. Please note – this snippet creates a notice; it does not change your shipping settings. WooCommerce shipping does not allow you to award free shipping based on quantity, so you will need to find a relative plugin/snippet for that. Once this is active, then you can customize this notice, but it’s 100% dependent on the plugin/snippet you select. Hope this makes sense ๐Ÿ™‚

    2. Thanks for your answer. I understand now. ๐Ÿ™‚

    3. No problem Amos, you’re welcome ๐Ÿ™‚

  38. Great Tips!! Just quick question. I’m using latest woocommerce and using Zone inside free shipping not the ‘woocommerce_free_shipping_settings’.
    Do you guys know the Zone’s inside free shipping?
    Thanks

    1. Hey Subin, thanks for your comment. I’m currently working on releasing an update to this snippet which would be compatible with Woo 2.6+. Hope to publish this soon ๐Ÿ™‚

    2. 2.6 compatible snippet has now been published ๐Ÿ™‚

  39. Does this also work with woocommerce 2.6+? I tried it out but it doesn’t work. I’m not sure that the problem is.

    1. Michael, thanks for your comment! Yes, indeed, you’re correct ๐Ÿ™‚ I’ll see if I have some time today to publish the updated version. Thanks a lot!

    2. That would be great. Thank you!

    3. 2.6 compatible snippet has now been published ๐Ÿ™‚

    4. Thank you very much. I implemented the snippet to my site. It works. But if I refresh the cart i get the following warning.

      Warning: min(): When only one parameter is given, it must be an array in /home/fsbswitz/public_html/subdomain/sidefyn/page/wp-content/themes/betheme_child/functions.php on line 98

      Line 98 is “$min_amount = min($min_amounts);” of your snippet.

      Do you have an idea to fix this?

    5. Michael, thanks so much for your comment! You’re right ๐Ÿ™‚ I just revised the snippet and wrapped the last part within a conditional check:

      if ( is_array($min_amounts) ) {
      ...
      }
      

      Let me know if this works!

    6. Thank you! It works.
      I’m looking for a solution to show this snippet also to not logged in users. Someone knows how to do that?

      I made the output multiligual. If some one need it…. I did it for French and German.

      /**
      * @snippet Notice with $$$ remaining to Free Shipping @ WooCommerce Cart
      * @how-to Watch tutorial @ https://businessbloomer.com/?p=19055
      * @sourcecode https://businessbloomer.com/?p=442
      * @author Rodolfo Melogli
      * @testedwith WooCommerce 2.6.4
      */
      
      function bbloomer_free_shipping_cart_notice_zones() {
      
      // Get Shipping Methods for Current Zone
      
      global $woocommerce;
      $shipping_methods = $woocommerce->shipping->get_shipping_methods();
      
      // Loop through the array to find min_amount value/s
      
      foreach($shipping_methods as $key => $value) {
          if ( $shipping_methods[$key]->min_amount > 0 ) {
            $min_amounts[$key] = $shipping_methods[$key]->min_amount;
          }
      }
      if ( is_array($min_amounts) ) {
      // Find lowest min_amount
      
      $min_amount = min($min_amounts);
      
      // Get Cart Subtotal inc. Tax excl. Shipping
      
      $current = WC()->cart->subtotal;
      
      // If Subtotal < Min Amount Echo Notice
      // and add "Continue Shopping" button
      
      if (ICL_LANGUAGE_CODE == 'fr')  {if ( $current < $min_amounts ) {
      echo '<div class="woocommerce-error"><a href="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . '" class="button wc-forward">Continuer vos achats</a>La livraison est gratuite si vous commandez ' . wc_price( $min_amount - $current ) . ' plus!</div>';
      }   } else  {if ( $current < $min_amounts ) {
      echo '<div class="woocommerce-error"><a href="' . get_permalink( woocommerce_get_page_id( 'shop' ) ) . '" class="button wc-forward">Weiter einkaufen</a>Es fehlen noch ' . wc_price( $min_amount - $current ) . ' bis zum kostenlosen Versand!</div>';
      }   }
       }
      }
      
      add_action( 'woocommerce_before_cart', 'bbloomer_free_shipping_cart_notice_zones' );
    7. Hey Michael, thanks for following up and sharing your WPML-friendly snippet version ๐Ÿ™‚ In regard to showing this to not logged in users – well, this already shows to not logged in users! Did you mean to “showing this to logged in users only” maybe?

    8. Hmm it is maybe something other. But I don’t see it if i’m not logged in

    9. In the WooCommerce settings, do you have a default shipping address or geolocation set up? Otherwise the system doesn’t know what country/zone you’re in once you’re on the Cart. Try this and let me know ๐Ÿ™‚

    10. You are the best!! That was it!

    11. Ahah excellent ๐Ÿ™‚

  40. Is it also possible to do something like this:

    – “You Only Need to Spend $$ to Get $4 discount”

    – “You Only Need to Spend $$ to Get $7 discount”

    – “You Only Need to Spend $$ to Get $10 discount”

    Thanks

    1. Hello Julian, thanks for your comment! Well, yes, I don’t see why not. You just need to tweak the line that starts with “echo”, and customize that according to your needs. Let me know how it goes!

  41. Sorry for the noob question, but where do I add these snippets?

    1. Fred, thanks for your comment – and no question is noob whatsoever ๐Ÿ™‚ You can place this in your child theme’s functions.php file – if you need more guidance, please take a look at this video tutorial: “How to Customize WooCommerce with PHP Snippets (even if you don’t know PHP)“. Hope this helps!

  42. Works great! Been looking for this for a while. Thank you!

  43. Great snippet Rofoldo!

    I wanted to use it on my checkout page rather than as a cart notice, so I made it into a shortcode (called “shipping35”. In case anyone else wants it, here is the code:

    
    // If your free shipping threshold is over $XX as per Woocommerce settings...
    
    function shipping35() {
    	$maximum = 35;
    	$current = WC()->cart->subtotal;
    
    // Format the difference as per Woo currency formatting settings
    	$formatteddifference = wc_price( $maximum - $current );
    		if ( $current < $maximum ) {
    		return 'Get free international shipping on all orders over $35 USD!</br></br>For free shipping on this order, just add <span style="font-weight: bold; font-size: 20px;">' . $formatteddifference . '</span> more! ';
    }
    		else {
    		return 'Great! You have FREE shipping on this order!';
    }
    }
    add_shortcode( 'shipping35', 'shipping35' );
    
    

    Hope that comes in useful for someone!

    Charlie

    1. Thank you very very very much Charlie!

    2. Hello Charlie!
      I have used your code on several sites, and it works very well, but recently one of our customers noticed an issue, when a coupon is used that makes the subtotal go below the amount required for free shipping, it still displays that free shipping is available.

      Is there any easy way to fix this?

    3. Thanks Mathias! I guess you’ll need to tweak the variable $current to account for that – hope this helps a little ๐Ÿ™‚

  44. Ciao Rodolfo,

    thanks for the useful woo-tips, always helpful.

    I modified the code so that the free shipping message displays the cart subtotal AFTER a coupon discount is applied, so it matches the correct threshold:

     $current = WC()->cart->cart_contents_total; 

    So changing “subtotal” to “cart_contents_total” seems to do the trick for me and the subtotal is calculated correctly with discount.

    Grazie!

    1. Gigio, thanks so much for your message and suggestion ๐Ÿ™‚ I’m sure many readers will be thankful too! Grazie ๐Ÿ™‚

  45. I would like to display this in the cart widget too – can it be done?

    Love the function!

    1. Linda, thanks for your feedback! And YES! You can do so by using the hook: “woocommerce_before_mini_cart”. I’m updating the code in a few minutes. Rodolfo

    2. I added this code and it seems to work – not sure it is the best way to do it:

      add_action( ‘woocommerce_before_checkout_billing_form’, ‘cart_notice’ );
      add_action( ‘woocommerce_widget_shopping_cart_before_buttons’, ‘cart_notice’ );

    3. Awesome Linda, thanks so much!

  46. Good day!

    Trying to get this to work with GPB but struggling. We have the thousand and decimal separator settings set in Woocommerce but the price is showing ยฃ2900.4 as we have ours set to ยฃ3000 minimum order delivery. Would ideally like this to show as ยฃ2,900.40 ๐Ÿ™‚

    Great snippet btw!

    Thanks ๐Ÿ™‚

    1. Hey thanks for your feedback! Try using wc_price($maximum – $current) and let me know if this does the trick!

    2. Thank you for the quick response ๐Ÿ™‚
      It resulted in Parse error: syntax error, unexpected ‘รขโ‚ฌโ€œ’ (T_STRING)

    3. Here’s the working snippet:

      function cart_notice() {
      $maximum = 1500;
      $current = WC()->cart->subtotal;
      $formatteddifference = wc_price( $maximum - $current );
      if ( $current < $maximum ) {
      echo '<div class="woocommerce-message">Get free shipping if you order ' . $formatteddifference . ' more!</div>';
      }
      }
      add_action( 'woocommerce_before_cart', 'cart_notice' );
      

      Hope this helps ๐Ÿ™‚

    4. Thanks for the quick response ๐Ÿ™‚
      Still spitting out the “Parse error: syntax error, unexpected โ€˜รขโ‚ฌโ€œโ€™ (T_STRING)” so not sure if it is the way my server is configured but thanks anyway ๐Ÿ˜€

    5. Yes, it seems you used some character that is not recognised by your system or forgot a “;” somewhere ๐Ÿ™‚

  47. If you don’t want to hardcode the maximum amount, you could fetch it from WooCommerce settings:

    https://gist.github.com/jukra/65373cde1d54770670e8

    1. Jukka, thanks so much for your valuable feedback!

  48. Thanks, that worked beautifully!

  49. Worked great. Is there a way to check to see if free shipping is available first? We run promos for a month that has the free shipping so basically we want it to check if free shipping is available as an option and if it is then display the message. That way we don’t have to comment out the code, we can just turn off the free shipping option in the settings.

    Also, is there a way in WC to pull the minimum dollar amount for the free shipping to apply rather than hard coding it?

    1. Travis, thank you for your feedback.

      Yes, of course you can check if “free shipping is available”! Take a look at our post and use a similar PHP conditional to only show the message if free shipping is not available.

      In relation to the other question, that’s another “of course”. Just go to Woocommerce / Settings / Shipping / Free Shipping and beside “Free Shipping Requires..” choose a minimum amount, then enter such amount in the field below.

      Hope this helps ๐Ÿ™‚

  50. Hi, is it possible to display this notice only when there actualy IS shipping cost? And hide it for downloadables and virtual?

    1. Hi Michal thanks for your message! Yes, I guess you could check if the cart contains virtual products, and if yes, decide not to show the notice. This is the PHP you can use to detect if there is a virtual product in the cart (source: http://www.remicorson.com/woocommerce-hide-checkout-fields-for-virtual-products):

      
        // By default, no virtual product
        $has_virtual_products = false;
        
        // Default virtual products number
        $virtual_products = 0;
        
        // Get all products in cart
        $products = $woocommerce-&gt;cart-&gt;get_cart();
        
        // Loop through cart products
        foreach( $products as $product ) {
      	  
      	  // Get product ID and '_virtual' post meta
      	  $product_id = $product['product_id'];
      	  $is_virtual = get_post_meta( $product_id, '๏ฟผ_virtual', true );
      	  
      	  // Update $has_virtual_product if product is virtual
      	  if( $is_virtual == 'yes' )
        		$virtual_products += 1;
        }
        
        if( count($products) == $virtual_products )
        	$has_virtual_products = true;
        
        return $has_virtual_products;
      
      
    2. I tried to glue it myself – with no luck ๐Ÿ˜‰

  51. oohhh man, i just found that my theme is doing something wrong with that, just tested the code on another site and it work like a charm…

    1. Great! Glad to hear that ๐Ÿ™‚

  52. good day, im trying the code but it didnt work, could u maybe help me what im doing wrong??
    im putting that code on my code/functions.php file.

    // If your free shipping threshold is 1500 as per Woocommerce settings…
    // …show a cart notice if order subtotal is less than 1500

    function cart_notice() {
    $maximum = 600;
    $current = WC()->cart->subtotal;
    if ( $current < $maximum ) {
    echo 'Recibe tu Envio Gratis $’ . ($maximum – $current) . ‘ mas!’;
    }
    }

    add_action( ‘woocommerce_before_cart’, ‘cart_notice’ );

    1. Renato, thanks for your comment! What version of Woocommerce are you on?

    2. hello, i been tried on the next 2 versions:
      WC: 2.1.8
      WC: 2.1.9

    3. I see. Try using this instead:

      
      function cart_notice() {
      global $woocommerce;
      $maximum = 600;
      $current = $woocommerce-&gt;cart-&gt;get_cart_subtotal();
      if ( $current &lt; $maximum ) {
      echo 'Recibe tu Envio Gratis $โ€™ . ($maximum โ€“ $current) . โ€˜ mas!โ€™;
      }
      }
      
      add_action( โ€˜woocommerce_before_cartโ€™, โ€˜cart_noticeโ€™ );
      
      
    4. well, just tried the code and didnt work. added the “” because make an error but it didnt show anything. updated my Woocommerce to the version 2.2.6 and still doesnt work.

  53. wow, thats fine! and simple!

    the german text snippet is

    “Nur noch ‘ . ($maximum – $current) . ‘ โ‚ฌ bis zur kostenlosen Lieferung!”

    so i have the โ‚ฌ after the difference price and a space between both.

    but two little problems:
    1: i need a comma between euros and cents, not a dot,
    2 and i need two digits after the comma

    is it possible top fix this?

    and an idea for the pro version – if you will do this to a plugin – it would be nice when it use the free delivery price from the woo settings. ๐Ÿ˜‰

    thanks and greetz .-)

    1. Reini, thanks for your comment. When I use this snippet on my test website, it gives me: “Get free shipping if you order $1498.98 more!”, so it correctly adds two decimals and the “dot”. Therefore, if you have this set up correctly under Woocommerce > Settings > General > Currency Options, it should do what you’re asking!

    2. thanks for your fast repley ๐Ÿ™‚

      the woocommerce settings with the comma, the two digits and the โ‚ฌ after with space ist the first step after installing woocommerce ๐Ÿ™‚

      i have a testshop too, the same problem, no digits for the cent (only prices without cents).
      in our not-test-shop now i have three digits, i think it is because the tax, it grabs the tax before rounding.

    3. Try this edit (see above function):

      if ( $current &lt; $maximum ) {
      setlocale(LC_MONETARY, 'de_DE');
      echo '&lt;div class=&quot;woocommerce-message&quot;&gt;Get free shipping if you order ' . money_format('%=*^-14#8.2i', ($maximum - $current)) . ' more!&lt;/div&gt;';
      }
      

      Reference: http://php.net/manual/en/function.money-format.php

    4. good morning and thank you, now the comma and the number of digits are ok ๐Ÿ™‚

      but i have 6 stars before the price -> screenshot: https://dl.dropboxusercontent.com/u/2455851/campbloomer/free-shipping-01.png

      the other thing is, that the snippet grabs the absolut summary including tax and delivery, right? i have a B2B-shop, so i need the difference between only the products summary – whitout tax and delivery – and the free delivery value.

      i think for B2C shops are also is the price without the delivery the right point. i hope you can understand me ๐Ÿ™‚

    5. oh, and i see “EUR โ‚ฌ” now …

    6. ok, the stars are placeholders. when i delete the star in the string between “=” and “^” and set a space, the its ok.

      money_format(‘%= ^-14#8.2i’,

      ๐Ÿ™‚

    7. sorry for spamming ๐Ÿ˜‰

      deleting the de_DE string is deleting the EUR, but it sets the comma to a dot back.

Questions? Feedback? Support? Leave your Comment Now!
_____

If you are writing code, please wrap it between: [php]code_here[/php]. Failure to complying with this (as well as going off topic) will result in comment deletion. You should expect a reply in about a week - this is a popular blog but I need to get paid work done first. Please consider joining #BloomerArmada to ask me 1-to-1 WooCommerce questions. Thank you :)

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.