Want to make sure customers order enough before they reach checkout? A WooCommerce minimum quantity checkout restriction can help you set a clear minimum for specific products and prevent checkout when a cart falls short.
With a simple WooCommerce snippet, you can check product quantities in the cart and show a helpful message explaining what the customer needs to add. It’s a straightforward way to support your store’s ordering requirements while making the checkout experience clear and friendly.
Set Up a WooCommerce Minimum Quantity Checkout Restriction
Before adding a checkout rule, decide exactly what “minimum” means for your store. A wholesale pack, for example, may require a certain quantity of one item, while a delivery threshold might count every eligible item in the cart.
Start by choosing whether your rule applies to selected products or to the cart as a whole. That choice determines what the snippet should count and helps prevent customers from being blocked for the wrong reason.
Choose the minimum quantity rule for individual products or the whole cart
For product-specific requirements, set a minimum for each qualifying product. If a customer needs to buy at least six candles, adding six of another product should not satisfy that rule. A product-level check compares the quantity of the required item against its own minimum.
A cart-wide rule works differently: it adds together quantities across the cart and checks the total. For example, a minimum of ten units could be met with four mugs and six plates. When planning a WooCommerce minimum quantity checkout restriction, make the intended rule clear in the message customers see, too.
- Choose product-level rules for case packs, wholesale items, or products with their own purchase minimums.
- Choose a cart-wide rule when any combination of eligible items can meet the threshold.
- Exclude items deliberately if samples, gift cards, or other products should not count toward the total.
Once the scope is clear, consider how the rule should behave when a cart contains different products or variations. These details matter because WooCommerce stores cart items as separate lines, even when they belong to a related product.
Decide how to handle mixed products and quantity variations
For variable products, determine whether the minimum applies to each variation separately or to all variations of the parent product combined. If customers can mix sizes or colors to reach a pack requirement, the snippet may need to total quantities across those variations rather than check each variation line on its own.
Mixed carts also need a consistent counting method. Decide whether the rule counts all units, only specified products, or product categories. Then make the checkout validation and notice match that choice—for example: “Add two more qualifying items to continue.” Test carts with multiple lines, changed quantities, and different variations to confirm the restriction responds correctly.
Add a snippet to block checkout when quantities are too low
With the counting rule decided, the next step is choosing where WooCommerce should enforce it. A validation hook can check the cart at the right point, then explain what the customer needs to do before placing an order.
The hook matters because it determines when your check runs and how its error appears. For a standard WooCommerce checkout, the following action is a practical place to start.
Select the right WooCommerce checkout validation hook
The woocommercecheckcartitems action lets you inspect cart contents during WooCommerce’s cart validation process. If the quantity is below your threshold, adding an error notice prevents the customer from proceeding until the cart is corrected.
This approach suits stores using the classic cart and checkout. If your store uses the Checkout Block, test the behavior on your setup; block-based checkout may require a Store API-compatible validation approach.
For a cart-wide minimum of ten units, add this code to a child theme’s functions.php file or a site-specific plugin. Change $minimum to the threshold you chose:
addaction( 'woocommercecheckcartitems', 'storecheckminimumcartquantity' );
function storecheckminimumcartquantity() {
if ( ! WC()->cart ) {
return;
}
$minimum = 10;
$quantity = 0;
foreach ( WC()->cart->getcart() as $item ) {
$quantity += (int) $item['quantity'];
}
if ( $quantity < $minimum ) {
$remaining = $minimum - $quantity;
wcaddnotice(
sprintf( 'Add %d more item(s) to your cart before checkout.', $remaining ),
'error'
);
}
}Test with a cart below and at the threshold. The first should show an error; the second should pass. This example counts every cart unit, so exclude products that should not count if your store has exceptions.
When only certain products have minimums, use a product-level check instead of the cart-wide total. The example below groups variations under their parent product ID, so customers can combine variations to meet that product’s minimum.
Add the minimum quantity check and display a clear error message
A useful notice tells shoppers both what is missing and how to fix it. Keep the wording specific, and calculate the shortfall from the current cart quantity rather than displaying a vague message such as “Minimum not met.”
For example, “Add 3 more items to your cart before checkout” gives customers a clear next step. Use “qualifying items” instead of “items” if only selected products count toward your rule.
After adding the snippet, verify that the notice appears when expected and clears once the minimum is reached. Also test quantity changes and cart updates, since validation should reflect the latest cart contents.
Adjust the snippet for product-specific minimums
For separate product thresholds, replace the cart-wide snippet with the version below; don’t run both unless you intentionally want both rules. Update the example IDs and minimums to match your products.
addaction( 'woocommercecheckcartitems', 'storecheckproductminimums' );
function storecheckproductminimums() {
if ( ! WC()->cart ) {
return;
}
$minimums = array(
123 => 6,
456 => 3,
);
$quantities = array();
foreach ( WC()->cart->getcart() as $item ) {
$productid = (int) $item['productid'];
$quantities[$productid] = ( $quantities[$productid] ?? 0 )
+ (int) $item['quantity'];
}
foreach ( $minimums as $productid => $minimum ) {
$quantity = $quantities[$productid] ?? 0;
if ( $quantity > 0 && $quantity < $minimum ) {
wcaddnotice(
sprintf(
'Add %d more unit(s) of product #%d before checkout.',
$minimum - $quantity,
$productid
),
'error'
);
}
}
}This version checks products that are already in the cart; it does not require customers to buy every listed product. Replace the product number in the notice with a product name or link if you want to make the instruction more shopper-friendly.
Test and troubleshoot your WooCommerce minimum quantity checkout restriction
A rule can work perfectly with one test cart and still behave differently when shoppers combine products, change quantities, or use another checkout layout. A few targeted checks now can catch those surprises before they affect real orders.
Start with the cases most likely to expose a counting or validation mismatch. The following checks help confirm that the snippet matches your store’s intended rule.
Check behavior with different cart combinations and checkout methods
Test more than just a cart that is one item below the threshold. Include mixed products, multiple cart lines for the same product, and variations, then confirm each result matches how your snippet counts units.
- Cart-wide rule: test whether different products combine to meet the total, and whether excluded items are ignored if you have customized the code.
- Product-specific rule: check that another product cannot make up a shortfall. If variations should count together, confirm their quantities are grouped as intended.
- Boundary cases: test an empty cart, a quantity below the minimum, the exact minimum, and a quantity above it.
Then try the checkout experience your customers use. The woocommercecheckcart_items approach is intended for classic WooCommerce cart and checkout flows; block-based checkout may need Store API-compatible validation. Review the relevant WooCommerce Cart and Checkout Blocks documentation and test on your actual setup.
If the result differs from your test, check whether another part of the site is changing cart quantities or checkout validation. These steps can help narrow down conflicts without changing the rule itself.
Resolve common issues with themes, plugins, and cached pages
Temporarily test on a staging site with a default theme and other plugins disabled, leaving WooCommerce and your snippet active. If the restriction then works, re-enable extensions one at a time to identify a conflict—especially plugins that alter checkout fields, cart rules, or notices.
Also make sure cart and checkout pages aren’t served from a full-page cache. Clear site, hosting, and browser caches after changing the code, then retest in a private browser window. If the notice appears repeatedly or fails to clear, check for duplicate snippets and confirm the validation function is registered only once.
Once the behavior is reliable, protect it from being lost during routine maintenance. A small regression check after updates can prevent a quiet checkout change from going unnoticed.
Keep the restriction working after WooCommerce updates
Keep custom code in a site-specific plugin or child theme, rather than editing WooCommerce core or a parent theme. Before updating WooCommerce, your theme, or checkout-related extensions, test the change on staging and keep a recent backup.
After each update, repeat the boundary and mixed-cart tests, then place a test order using the checkout method your store supports. If validation stops working, review the WooCommerce and extension changelogs and check for PHP errors before adjusting the snippet.
Make minimum quantities clear before customers check out
A well-planned WooCommerce minimum quantity checkout restriction helps your store enforce ordering requirements without leaving shoppers guessing. Choose whether the minimum applies to individual products or the cart, and make sure mixed items and variations are counted the way your business intends.
With the right validation approach and a clear notice, customers can quickly understand what they need to add. Test different cart combinations and checkout methods, and revisit the rule after site updates to keep it working reliably.
Once the restriction is in place, you can protect your minimum order requirements while giving customers a smoother path to checkout.