Skip to content
Blog Careers Google Partner 12+ Years · 5000+ Projects
Best Website design company in India October 29, 2021 2 min read

Set minimum order amount in woocommerce

A WooCommerce minimum order amount stops customers from checking out until their cart reaches a value you choose. It is useful when small orders cost more to pack and deliver than they earn. WooCommerce has no setting for this, so the simplest way is a short code snippet.

How to set a WooCommerce minimum order amount

Open Appearance> Theme editor> paste the code as below

Theme editor where the WooCommerce minimum order amount code goes

add_action( ‘woocommerce_check_cart_items’, ‘required_min_cart_subtotal_amount’ );
function required_min_cart_subtotal_amount() {

// HERE Set minimum cart total amount
$minimum_amount = 250;

// Total (before taxes and shipping charges)
$cart_subtotal = WC()->cart->subtotal;

// Add an error notice is cart total is less than the minimum required
if( $cart_subtotal < $minimum_amount ) {
// Display an error message
wc_add_notice( ‘<strong>’ . sprintf( __(“A minimum total purchase amount of %s is required to checkout.”), wc_price($minimum_amount) ) . ‘<strong>’, ‘error’ );
}
}

Cart notice for the WooCommerce minimum order amount

 

Job Done

How the minimum order amount snippet works

The code runs every time WooCommerce checks the cart. First, it reads the cart subtotal. Then it compares that figure with the minimum you set in $minimum_amount, which is 250 in the example. If the subtotal is lower, the customer sees an error notice and cannot place the order until they add more items.

Change 250 to your own amount. Because the check uses the cart subtotal, shipping charges do not count towards the minimum.

Before you paste the code

  • Use a child theme or a code snippets plugin, because a theme update overwrites changes made in the parent theme’s functions.php. WordPress explains child themes in its developer handbook.
  • Take a backup first, since a typing mistake in functions.php can bring the site down.
  • Test with a small cart and a large cart, on mobile as well as desktop.

If you would rather have this set up and tested for you, see our WooCommerce development services or our e-commerce website development in Bhubaneswar.

See also: Clear cart data before adding new and Redirect to custom url after woocommerce checkout.

Keep Reading

Related Articles

View All Articles