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' );
 
        }

    }
 
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: How to Fix the “Cart is Empty” Issue
    For some reason, sometimes you add products to cart but the cart page stays empty (even if you can clearly see the cart widget has products in it for example). But don’t worry – it may just be a simple cache issue (and if you don’t know what cache is that’s no problem either) or […]
  • 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 the cart in order to qualify for free shipping. It’s pure psychology. Here’s how we show a simple message on the […]
  • WooCommerce: Cart and Checkout on the Same Page
    This is your ultimate guide – complete with shortcodes, snippets and workarounds – to completely skip the Cart page and have both cart table and checkout form on the same (Checkout) page. But first… why’d you want to do this? Well, if you sell high ticket products (i.e. on average, you sell no more than […]
  • WooCommerce: Disable Payment Method If Product Category @ Cart
    Today we take a look at the WooCommerce Checkout and specifically at how to disable a payment gateway (e.g. PayPal) if a specific product category is in the Cart. There are two tasks to code in this case: (1) based on all the products in the Cart, calculate the list of product categories in the […]
  • WooCommerce: Add Privacy Policy Checkbox @ Checkout
    Here’s a snippet regarding the checkout page. If you’ve been affected by GDPR, you will know you now need users to give you Privacy Policy consent. Or, you might need customer to acknowledge special shipping requirements for example. So, how do we display an additional tick box on the Checkout page (together with the existing […]

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. Follow @rmelogli

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? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. 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 the Business Bloomer Club to get quick WooCommerce support. Thank you!

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