Use the coupon code BLACKFRIDAY40 and save 40% OFF! Buy Now

Set a minimum order amount for WooCommerce orders

Posted On
Set a minimum order amount for WooCommerce orders WordPress template

It is not uncommon for store owners to have the need to set a minimum order amount before any order can be completed. This can be due to handling, processing and/or shipping costs making the sale unprofitable. Today we’re going to add a small snippet to our theme which will allow store owners to set a minimum order amount for all their orders.

Install and activate a child theme

As always the first step on our process here is to create and install a child theme. If you are using one of our themes you can easily grab its child theme from our downloads section. If not, you can read our beginner’s guide on child themes to create your own. This step is essential in order to preserve our changes throughout theme updates.

All code below will be placed in our child theme’s functions.php file. If the file is empty the code will go just below the opening <?php tag, otherwise, if it has contents, the code should be placed at the end of the file, before the closing ?> PHP tag if it exists.

Add the code to set the minimum order amount

add_action( 'woocommerce_checkout_process', 'cssigniter_set_minimum_order_amount' );
add_action( 'woocommerce_before_cart', 'cssigniter_set_minimum_order_amount' );

function cssigniter_set_minimum_order_amount() {
// Change the number below to modify the minimum amount.
$minimum = 50;

if ( WC()->cart->total < $minimum ) {

if ( is_cart() ) {

wc_print_notice(
sprintf(
/* translators: %1$s: current order total %2$s: minimum order total */
__( 'Your current order total is %1$s — you must have an order with a minimum of %2$s to place your order ', 'your-text-domain' ),
wc_price( WC()->cart->total ),
wc_price( $minimum )
),
'error'
);

} else {

wc_add_notice(
sprintf(
/* translators: %1$s: current order total %2$s: minimum order total */
__( 'Your current order total is %1$s — you must have an order with a minimum of %2$s to place your order ', 'your-text-domain' ),
wc_price( WC()->cart->total ),
wc_price( $minimum )
),
'error'
);

}
}
}

In line 6 above you can customize the minimum order amount. With the code in place the user will get a notice on the cart page regarding the minimum order amount if their order does not exceed it. Furthermore if they proceed to the checkout and try to place the order they will be presented with the same error notice regarding the minimum order amount.

Wrapping up

This quick guide has helped us set a minimum order amount, orders below that amount will get a notice informing the customers that they need to increase their cart total otherwise they won’t be able to proceed with order placement. Let us know if this guide has helped you on your WooCommerce based store, and interesting ideas you might have for future guides in the comments below.

One response to “Set a minimum order amount for WooCommerce orders”

  1. Mindaugas says:

    This takes in the acount taxes and delivery.
    If you want to calculate based on product value in the cart, then replace total to subtotal in the code

    if ( WC()->cart->subtotal cart->subtotal ),

Leave a Reply

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

Get access to all WordPress themes & plugins

24/7 Support Included. Join 115,000+ satisfied customers.

Pricing & Sign Up

30-day money-back guarantee. Not satisfied? Your money back, no questions asked.

Back to top