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 on the Checkout Page if the order is below a set threshold.
Of course, it’s also up to you to let customers know there is a minimum before reaching the Cart/Checkout, so this could come as a notification in the single product page, shop page or even the header if it’s a strict business requirement.
Enjoy!
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 8
* @community https://businessbloomer.com/club/
*/
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' );
}
}
}
Advanced Plugin: WooCommerce Quantity Manager
For those of you who arenβt comfortable working with code, I also researched plugins that offer the same functionality.
My recommendation is Barn2βs WooCommerce Quantity Manager, which lets you define a minimum order value or quantity. It also comes with other quantity management features such as maximum quantities and step values.
this is not working for me with the new style woocommerce basket and checkout blocks
They are not *easily* customizable at the moment. I suggest you revert to the default shortcodes if you want to customize them.
So, hey, great snippet, thank you big time! How can I actually lock the Checkout button if the order is under minimum?
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!
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
Not sure I fully understand?
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.
Awesome!
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.
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!
Thank you for providing us with thisβ¦I would like to know how I can omit this minimum rule for digital purchases
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!
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
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
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.
We would like to use the code, depending on the country, so all countries in Europe should mim. 50 Euros.
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
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?
Hello there, thanks for your comment! Not sure I fully understand it though π
Hello, how would the code be if the minimum should be without tax? Thank you
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
Thank you for this modification. It works just fine!
Awesome π
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?
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
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!
Mike, that sounds like custom work… sorry but I can’t help here π
Rodolfo,
Can we switch the minimum to maximum?
$maximum= 500; // change this to your maximum order amount
if ( WC()->cart->subtotal > $maximim ) {
Of course π
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.
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.
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?
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!
Hi, is there a way of excluding the delivery charge from the total?
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!
*like this – FREE Delivery on orders over βΉ499.00
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 π
hi Rodolfo, i want to show minimum amount for free shipping on cart and check out page. How can i do this?
Hi, is it possible to define a minimum order for shipping but not have this requirement if it is local pickup? Thank you
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?
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?
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 π
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?
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/
Hi very good, thank you… but I need something more… How do I make that text
be translated with wpml or “loco translator”
Please, can you help me… thank you again
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 π
Hello
Can you tell me where I insert this code?
Sorry for my Google english π
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!
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.
Awesome, thanks a lot Daymobrew π Your input is much appreciated!