search

Set Minimum Order Amount in WooCommerce

If you want to require a minimum order amount in your WooCommerce store, add the following code to your functions.php file. The code displays a notice in the cart and prevents checkout. For more on WooCommerce hooks.

add_action( 'woocommerce_checkout_process', function() {
	$minimum = 50;
	if ( WC()->cart->get_subtotal() < $minimum ) {
		wc_add_notice(
			sprintf( 'The minimum order amount is %s. Your current cart total is %s.',
				wc_price( $minimum ),
				wc_price( WC()->cart->get_subtotal() )
			), 'error'
		);
	}
} );

add_action( 'woocommerce_before_cart', function() {
	$minimum = 50;
	if ( WC()->cart->get_subtotal() < $minimum ) {
		wc_print_notice(
			sprintf( 'The minimum order amount is %s. Please add more products to your cart.',
				wc_price( $minimum )
			), 'notice'
		);
	}
} );

Replace 50 with your desired minimum amount.

Join the Discussion
0 Comments  ]

Leave a Comment

To add code, use the buttons below. For instance, click the PHP button to insert PHP code within the shortcode. If you notice any typos, please let us know!

Savvy WordPress Development official logo