Set a minimum order amount
Require a minimum cart total before customers can check out in WooCommerce, with a clear message. Works with block and classic checkout.
// Block checkout until the cart reaches a minimum amount.
add_action(
'woocommerce_check_cart_items',
function () {
$minimum = 20; // In your store currency.
if ( ! WC()->cart || WC()->cart->is_empty() ) {
return;
}
// Uses the subtotal as shown to customers (with or without tax, per your settings), before shipping.
$subtotal = (float) WC()->cart->get_displayed_subtotal();
if ( $subtotal < $minimum ) {
wc_add_notice(
sprintf(
'The minimum order amount is %1$s. Your basket is currently %2$s.',
html_entity_decode( wp_strip_all_tags( wc_price( $minimum ) ), ENT_QUOTES, 'UTF-8' ),
html_entity_decode( wp_strip_all_tags( wc_price( $subtotal ) ), ENT_QUOTES, 'UTF-8' )
),
'error'
);
}
}
);
What it does
If small orders cost you more to pack and ship than they earn, you can set a minimum order amount.
This snippet shows an error and blocks checkout while the cart subtotal is below the amount you set. Change $minimum to your amount. The subtotal is taken before shipping, with or without tax to match how your shop shows prices.
Good to know
- Works with the block cart and checkout and with the classic ones. In the classic checkout, the message shows on the cart page.
- Coupons that lower the subtotal can take an order below the minimum.