How to Add a Minimum Order Amount to WooCommerce Checkout
Set a WooCommerce checkout minimum with PHP, show shoppers how much more to add, and validate orders correctly in both classic and block checkout layouts.
Last updated:
Reviewed for accuracy by Jesse Nickles
Choose what counts toward the minimum
WooCommerce has no built-in minimum order setting. This PHP example requires at least 50 in your store's currency in products after coupon discounts. Shipping, taxes, and fees do not count. A cart with 49 in products fails the check; a cart with exactly 50 passes. A cart with 55 in products and a 10 coupon totals 45 after the discount, so it fails and the message asks the shopper to add 5 more.
The code uses get_cart_contents_total() for the discounted product subtotal. If you want to measure the amount before coupons instead, replace that method with get_subtotal(); the 55 cart with a 10 coupon would then qualify. This rule prevents placing an undersized order. To charge a fee instead of blocking checkout, see the small-order fee guide.
Add the checkout validation
Back up your store and test this change on staging first. Add the PHP below to your active child theme's functions.php or a site-specific plugin. Do not add another opening <?php tag inside an existing PHP file. HoverCraft users can follow the child theme instructions; editing the parent theme can cause changes to be lost after an update.
function myshop_minimum_order_message( $cart ) {
if ( ! $cart || $cart->is_empty() ) {
return '';
}
$minimum = 50.00;
$current = (float) $cart->get_cart_contents_total();
if ( $current >= $minimum ) {
return '';
}
return sprintf(
'Add %1$s more to reach the %2$s minimum order amount.',
wp_strip_all_tags( html_entity_decode( wc_price( $minimum - $current ), ENT_QUOTES, get_bloginfo( 'charset' ) ) ),
wp_strip_all_tags( html_entity_decode( wc_price( $minimum ), ENT_QUOTES, get_bloginfo( 'charset' ) ) )
);
}
add_action( 'woocommerce_checkout_process', function () {
$message = myshop_minimum_order_message( WC()->cart );
if ( $message && ! wc_has_notice( $message, 'error' ) ) {
wc_add_notice( $message, 'error' );
}
} );
add_action( 'woocommerce_checkout_validate_order_before_payment', function ( $order, $errors ) {
$message = myshop_minimum_order_message( WC()->cart );
if ( $message ) {
$errors->add( 'myshop_minimum_order', $message );
}
}, 10, 2 );
Replace 50.00 with the minimum in your store's currency. Replace myshop in both the function name and error code with a prefix unique to your site. The function checks the cart's discounted product amount and returns an error message only when the amount falls short. It uses wc_price() to format both the minimum and the amount still needed. Do not compare the final cart total for this rule: it includes charges beyond the products and can change with the delivery address.
Understand classic and block checkout
The two hooks run in different checkout flows. woocommerce_checkout_process adds an error notice when a shopper submits the classic shortcode checkout. In the Checkout Block, woocommerce_checkout_validate_order_before_payment adds the message to a WP_Error object during server-side validation before payment. Together, they enforce the same minimum in either layout. The block-specific hook is available from WooCommerce 9.9; older installations need an update or a compatible alternative.
The shopper can still add products below 50 to the cart. The example displays its error only when they attempt to place an order; it does not show a persistent cart-page warning. For settings managed in WP Admin, cart-page notices, or separate limits by product, category, customer role, or delivery location, consider the WooCommerce Minimum Order Amount extension. It offers a storewide restriction or conditional rules, including support for classic and block checkout, whereas the snippet enforces one fixed threshold.
Test the amount and error messages
- Try products totaling 49, exactly 50, and 55 in your store's currency. The first should fail at checkout; the other two should pass this minimum check.
- Apply a 10 coupon to the 55 cart. With the default after-discount rule, confirm it now fails and the message asks for 5 more. If you switched to
get_subtotal(), confirm it passes instead. - Check a store displaying tax-inclusive prices and add shipping charges. The rule should still measure the discounted product subtotal before tax, shipping, and fees.
- Test the actual classic or block checkout your store uses, as a guest and a signed-in customer. Confirm the error appears on submission and a cart below the minimum cannot proceed to payment.
If the check does not run, verify that the child theme or plugin loads the PHP, the WooCommerce version supports the checkout hook you need, and there are no PHP errors. If the required amount looks wrong, check tax display settings and whether you intended to calculate before or after coupons. Retest after major WooCommerce or checkout-extension updates.