WooCommerce: Define a Minimum Order Amount

Today we take a look at the WooCommerce Minimum Order Amount. This snippet displays an error notification on the Cart Page and an error message @ Checkout Process if the order is below a set threshold.

WooCommerce Minimum Order Value
WooCommerce Minimum Order Value

PHP Snippet: Define a Minimum Order Amount and Show Error Messages @ Cart & Checkout

/**
 * @snippet       WooCommerce: Define Minimum Order Amount & Show Errors
 * @how-to        Get CustomizeWoo.com FREE
 * @author        Rodolfo Melogli
 * @compatible    WooCommerce 3.8
 * @donate $9     https://businessbloomer.com/bloomer-armada/
 */
 
add_action( 'woocommerce_checkout_process', 'bbloomer_wc_minimum_order_amount' );
add_action( 'woocommerce_before_cart', 'bbloomer_wc_minimum_order_amount' );
  
function bbloomer_wc_minimum_order_amount() {
     
    $minimum = 25; // change this to your minimum order amount
 
    if ( WC()->cart->subtotal < $minimum ) {
 
        if ( is_cart() ) {
 
            wc_print_notice( 
                sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' );
 
        } else {
 
            wc_add_notice( 
                sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' , wc_price( $minimum ), wc_price( WC()->cart->subtotal ) ), 'error' );
 
        }

    }
 
}
Was this article helpful?
YesNo

Where to add custom code?

You should place PHP snippets at the bottom of your child theme functions.php file and CSS at the bottom of its style.css file. Make sure you know what you are doing when editing such files - if you need more guidance, please take a look at my guide "Should I Add Custom Code Via WP Editor, FTP or Code Snippets?" and my video tutorial "Where to Place WooCommerce Customization?"

Does this snippet (still) work?

Please let me know in the comments if everything went 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.

If you think this code saved you time & money, feel free to join 17,000+ WooCommerce Weekly subscribers for blog post updates and 250+ Business Bloomer supporters for 365 days of WooCommerce benefits. Thank you in advance!

Need Help with WooCommerce?

Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent 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.

48 thoughts on “WooCommerce: Define a Minimum Order Amount

  1. So, hey, great snippet, thank you big time! How can I actually lock the Checkout button if the order is under minimum?

    1. Hey Andrei, 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. Hello!!

    great contribution to my shop.
    But since the last update, it has stopped working, now on screen it looks wrong.
    to see an exemple buy a code 3.970

    Thank you so much

    1. Not sure I fully understand?

  3. Great snippet. It seems that, contrary to documentation, the woo cart subtotal does include taxes though! (or maybe there is a bug in one of my plugins). Anyway I used

    WC()->cart->get_cart_contents_total()

    and it worked. It seems it includes discounts, but that works for me.

    1. Awesome!

  4. Hi — great snipplet thank you.
    How can I relax the minimum rule, lets say if the shipping method is set to ‘collection from store’?
    Many thanks.

    1. Turgut, 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!

  5. Thank you for providing us with thisโ€ฆI would like to know how I can omit this minimum rule for digital purchases

    1. Hello Veronica, 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!

  6. Hi thanks for the code but if you click on the checkout button on the cart, it still check out. It should be doing so until the minimum order is validated

    1. Hello Isaac, thanks for your comment! This snippet does not deny access to the Checkout, however it prints an error there. Unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. Thanks a lot for your understanding! ~R

    2. To deny access to the checkout page —
      Disable these two hooks —
      add_action( ‘woocommerce_checkout_process’, ‘bbloomer_wc_minimum_order_amount’ );
      add_action( ‘woocommerce_before_cart’ , ‘bbloomer_wc_minimum_order_amount’ );

      Use this instead:
      add_action( ‘woocommerce_check_cart_items’, ‘bbloomer_wc_minimum_order_amount’ );

      It will give the customer an warning when reaching the checkout unless purchase requirement is met.

  7. We would like to use the code, depending on the country, so all countries in Europe should mim. 50 Euros.

    1. Hello Tom, thanks so much for your comment! Yes, this is possible – 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

  8. Hello Rudolph, thanks for the tutorial, but would you like to know how to cook the minimum purchase per state and a personalized message appear?

    1. Hello there, thanks for your comment! Not sure I fully understand it though ๐Ÿ™‚

  9. Hello, how would the code be if the minimum should be without tax? Thank you

    1. Hello there – 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

  10. Thank you for this modification. It works just fine!

    1. Awesome ๐Ÿ™‚

  11. Rodolfo,
    Really nice your tutorials! It is helping me a lot!!!
    I do have a doubt, and if I would like to add the minimum of $1500 just if any product of the category 487 is on the cart?

    1. Hello Frederico, 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

  12. Great script, but how do I : –
    Allow any quantity for local pickup,
    But minimum order for delivery is ยฃ30
    and then restrict sale by hiding button.
    I have tried, but the update quantity mucks things up. (ajax call)
    I can hide button via jquery, css on load etc but putting it all together with the button clicks if you change shipping methods is creating way too much code. It has to be simpler than what I’m doing!

    1. Mike, that sounds like custom work… sorry but I can’t help here ๐Ÿ™‚

  13. Rodolfo,

    Can we switch the minimum to maximum?

    $maximum= 500; // change this to your maximum order amount

    if ( WC()->cart->subtotal > $maximim ) {

  14. Hi Rodolfo,

    I’ve a little issue with this snippet, the message is in 3 line, it is maybe a css problem but I’m not sure how to solve it.

    additionnaly I want only display the minmum amount not the actual cart amount

    is that code correct ?

    I'm using jupiter theme.

    1. Oscar, thanks for your comment! Yes, the snippet is correct, so you’re right, you have to fix your CSS. For the other issue, you have to work on the “sprintf” call.

  15. This adds a nice warning but I can still go to the cart. Is there a way to actually stop them from placing the order?

    1. Hey MadDog ๐Ÿ™‚ Yes, you can add some PHP to “deny checkout”. Just do a search on this site for “deny checkout” snippet and you’ll possibly learn how to do that given your if>then statement ๐Ÿ™‚ Hope this helps!

  16. Hi, is there a way of excluding the delivery charge from the total?

    1. Hey O Baba, thanks for your comment! Yes, you could try with other calls that can be found in https://docs.woocommerce.com/wc-apidocs/class-WC_Cart.html. For example, get_total_ex_tax(). Let me know!

  17. *like this – FREE Delivery on orders over โ‚น499.00

    1. Hey Pandey, thanks so much for your comment! This article should help: https://businessbloomer.com/woocommerce-add-need-spend-x-get-free-shipping-cart-page/. Let me know ๐Ÿ™‚

  18. hi Rodolfo, i want to show minimum amount for free shipping on cart and check out page. How can i do this?

  19. Hi, is it possible to define a minimum order for shipping but not have this requirement if it is local pickup? Thank you

    1. Hello Grace, thanks very much for your comment! The thing is that users don’t select the shipping method until the very end (on the checkout page)… so this message could only be displayed when such selection is made, and only on the checkout (not on the cart or single product page, as we can’t “read” something tat hasn’t been selected yet). This is custom work of course, but would the above suit?

      1. Thank you for your reply. Would I be able to use the above code to display minimum only for shipping and not require it for pickup on the checkout page?

        1. Well, yes the code would be a good start, but obviously some additional PHP needs to be put in place to detect the shipping and enable/disable the minimum order amount. Happy coding ๐Ÿ™‚

  20. Hi,
    I need something similar to this, but I need to restrict a particular product to a minimum order quantity of 25. Could this be done?

    1. Thanks for your comment Andy ๐Ÿ™‚ Yes, of course, you can just run this PHP function only for a certain product ID – take a look at this guide and see if you find the right conditional check: https://businessbloomer.com/woocommerce-conditional-logic-ultimate-php-guide/

  21. Hi very good, thank you… but I need something more… How do I make that text

    sprintf( 'You must have a minimum order amount of %s to place your order. Your current order total is %s.' ,

    be translated with wpml or “loco translator”

    Please, can you help me… thank you again

    1. Hey Juan, thanks a million for your comment! This is actually very simple, just check this example with sprintf: https://codex.wordpress.org/I18n_for_WordPress_Developers/#HTML. Let me know ๐Ÿ™‚

  22. Hello
    Can you tell me where I insert this code?
    Sorry for my Google english ๐Ÿ™‚

    1. Sanai, no problem at all! 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!

  23. One suggestion: Execute the sprintf() call before the is_cart() check and then use that string in the wc_print_notice() and wc_add_notice() calls. If you ever need to change the string you only have to change it in one place.

    1. Awesome, thanks a lot Daymobrew ๐Ÿ™‚ Your input is much appreciated!

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

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

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