Controlling how many units a customer can buy per variation is essential for inventory management, promotional campaigns, and wholesale pricing. WooCommerce doesn’t support per-variation quantity limits out of the box, but with the right plugin or a small code snippet, you can enforce minimum and maximum purchase quantities on each product variation.
This guide covers built-in WooCommerce stock controls, plugin-based solutions for min/max quantity limits, custom code approaches, and real store scenarios where variation-level quantity limits make a difference.
Why Set Quantity Limits Per Variation?
There are several practical reasons to control purchase quantities at the variation level rather than the product level:
- Stock protection: Prevent a single customer from buying out your entire stock of a popular size or color.
- Fair distribution: During product launches or limited drops, ensure more customers get a chance to purchase.
- Wholesale minimums: Require a minimum order quantity for bulk variations while allowing single-unit purchases on retail variations.
- Promotional control: Limit discounted variations to a maximum of 2-3 per customer to prevent abuse.
- Sample management: Allow only 1 unit of sample-size variations per order.
Method 1: WooCommerce Built-In Stock Management
WooCommerce includes basic stock management that can partially address quantity limits, though it’s limited in scope.
Per-variation stock quantity
- Edit your variable product and go to the Variations tab.
- Expand a variation and check Manage stock?
- Set the Stock quantity, this acts as an implicit maximum (customers can’t buy more than what’s in stock).
- Set Allow backorders? to “Do not allow” to enforce the limit strictly.
Sold individually
In the Inventory tab of the parent product, check Sold individually to limit the entire product to 1 unit per order. This applies to all variations combined, not per variation, so it’s a blunt instrument.
For true per-variation min/max limits, you need a plugin or custom code.
Method 2: Min/Max Quantities Plugin
The most straightforward solution is the WooCommerce Min/Max Quantities extension.
Setup steps
- Install and activate the plugin from Plugins > Add New.
- Edit your variable product and go to the Variations tab.
- Expand each variation, you’ll see new fields added by the plugin:
- Minimum quantity: The fewest units a customer must add (e.g., 2 for wholesale)
- Maximum quantity: The most units allowed per order (e.g., 5 for limited items)
- Group of: Force quantities in multiples (e.g., multiples of 6 for a six-pack)
- Set the limits for each variation independently.
- Click Save Changes and Update.
Plugin behavior
When a customer tries to exceed the maximum or go below the minimum, WooCommerce displays a notice on the cart page explaining the limit. The quantity input on the product page also respects the min/max/step values.
Alternative plugins
- Product Quantity for WooCommerce (free), Set min, max, and step values per product. Limited variation-level support in the free version.
- Min Max Control (free), Basic min/max with category-level rules.
- WooCommerce Quantity Manager, Advanced rules including role-based limits, category limits, and per-variation controls.
Method 3: Custom Code for Per-Variation Limits
If you want to avoid a plugin for something simple, here’s a code snippet that enforces per-variation maximum quantities using a custom field:
// Add max quantity field to variation settings
add_action( 'woocommerce_variation_options_pricing', 'add_variation_max_qty_field', 10, 3 );
function add_variation_max_qty_field( $loop, $variation_data, $variation ) {
woocommerce_wp_text_input( array(
'id' => "_max_qty_{$loop}",
'name' => "_max_qty[{$loop}]",
'label' => __( 'Max Quantity', 'woocommerce' ),
'desc_tip' => true,
'description' => __( 'Maximum purchase quantity for this variation.', 'woocommerce' ),
'type' => 'number',
'value' => get_post_meta( $variation->ID, '_max_qty', true ),
) );
}
// Save the field
add_action( 'woocommerce_save_product_variation', 'save_variation_max_qty_field', 10, 2 );
function save_variation_max_qty_field( $variation_id, $loop ) {
if ( isset( $_POST['_max_qty'][ $loop ] ) ) {
update_post_meta( $variation_id, '_max_qty', absint( $_POST['_max_qty'][ $loop ] ) );
}
}
// Enforce the limit in cart validation
add_filter( 'woocommerce_add_to_cart_validation', 'validate_variation_max_qty', 10, 5 );
function validate_variation_max_qty( $passed, $product_id, $quantity, $variation_id = 0, $variations = array() ) {
if ( ! $variation_id ) return $passed;
$max_qty = get_post_meta( $variation_id, '_max_qty', true );
if ( ! $max_qty ) return $passed;
// Check existing cart quantity for this variation
$cart_qty = 0;
foreach ( WC()->cart->get_cart() as $cart_item ) {
if ( $cart_item['variation_id'] == $variation_id ) {
$cart_qty += $cart_item['quantity'];
}
}
if ( ( $cart_qty + $quantity ) > $max_qty ) {
wc_add_notice( sprintf(
__( 'You can only purchase a maximum of %d units of this variation.', 'woocommerce' ),
$max_qty
), 'error' );
return false;
}
return $passed;
}
Add this code to your theme’s functions.php or a site-specific plugin. It adds a “Max Quantity” field to each variation in the admin and validates the limit when customers add items to the cart.
Real Store Scenarios
Scenario 1: Limited edition sneaker drop
You’re selling a limited edition shoe with sizes US 7-13. Stock is 50 pairs per size. Set maximum quantity to 1 per variation per order to ensure fairness. Combined with WooCommerce’s stock management, this prevents hoarding.
Scenario 2: Wholesale t-shirt printing
You offer custom t-shirts in S/M/L/XL. For wholesale customers, set a minimum of 12 per size (one dozen). For retail, keep the minimum at 1. Use role-based quantity rules (via WooCommerce Quantity Manager) to apply different limits per customer role.
Scenario 3: Free samples
You offer a “Sample” variation alongside full-size products. Set the sample variation’s maximum to 1 and minimum to 1. Set the full-size variation’s minimum to 1 with no maximum.
Troubleshooting
Quantity input not respecting limits on the product page
The HTML quantity input needs min, max, and step attributes. Some themes override WooCommerce’s default quantity input template. Check your theme’s woocommerce/global/quantity-input.php template override and ensure it passes through the min_value, max_value, and step arguments.
Limits not applying to variations specifically
If limits apply to the parent product instead of individual variations, your plugin may not support variation-level limits. Verify in the plugin documentation. The WooCommerce Min/Max Quantities official extension supports this; many free alternatives don’t.
Cart allows exceeding the limit when adding the same variation twice
The cart validation hook must check existing cart quantities plus the new quantity. The code snippet above handles this correctly. If using a plugin, ensure it validates against existing cart contents, not just the current add-to-cart request.
Best Practices
- Display limits clearly on the product page. Customers shouldn’t discover limits only at checkout.
- Set sensible defaults. A minimum of 1 and no maximum is the standard. Only restrict when there’s a business reason.
- Test with caching plugins. Page caching can sometimes serve stale quantity inputs. Exclude cart and checkout pages from caching.
- Consider user roles. Wholesale and retail customers often need different limits on the same variations.
- Document your limits in your shipping/FAQ page so customers know what to expect before adding items to cart.
How to Apply Multiple Shipping Classes to Variable Products in WooCommerce
