Skip to content
WooCommerce

How to Set Quantity Limits for Product Variations in WooCommerce

· · 11 min read
Quantity Limits for WooCommerce

Controlling how many units a customer can buy per variation matters 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 independently.

This guide covers the built-in WooCommerce stock controls, plugin-based min/max solutions, custom code approaches, and the store scenarios where variation-level quantity limits actually change your bottom line.

Why Set Quantity Limits Per Variation?

Stock protection is the obvious one: without a per-variation cap, a single customer can buy out your entire supply of a popular size or color in one order, leaving everyone else locked out for weeks. Fair distribution matters during product launches and limited drops, where a hard cap of one or two units per customer spreads a small batch across more buyers instead of letting the first person in line clear the shelf.

Wholesale minimums are a different problem entirely. You might require a case-size minimum on bulk variations while still allowing single-unit purchases on the retail version of the same product. Promotional control matters too, capping a heavily discounted variation at two or three per customer keeps a flash sale from turning into a reseller free-for-all. And sample management is its own small case: a “sample size” variation usually needs a hard limit of exactly one per order, no more, no fewer.

Method 1: WooCommerce Built-In Stock Management

WooCommerce includes basic stock management that partially addresses this, though it’s limited in what it actually controls.

Per-variation stock quantity

  1. Edit your variable product and open the Variations tab.
  2. Expand a variation and check Manage stock?
  3. Set the Stock quantity. This acts as an implicit maximum, since a customer can never buy more units than exist in stock.
  4. Set Allow backorders? to “Do not allow” if you want that implicit maximum enforced strictly rather than treated as a soft warning.

Sold individually

In the Inventory tab of the parent product, checking Sold individually limits the entire product to one unit per order. This applies across all variations combined, not per variation, which makes it a blunt instrument. If you check this box, a customer can buy one unit of any single variation, not one of each of five different sizes. For true per-variation min/max limits, you need a plugin or custom code, which is what the rest of this guide covers.

Method 2: Min/Max Quantities Plugin

The most direct route is the official WooCommerce Min/Max Quantities extension from WooCommerce.com.

Setup steps

  1. Install and activate the plugin from Plugins > Add New.
  2. Edit your variable product and open the Variations tab.
  3. Expand each variation. You’ll see new fields the plugin adds: a Minimum quantity field (the fewest units a customer must add, useful for wholesale minimums like 2), a Maximum quantity field (the most units allowed per order, useful for limited items), and a Group of field that forces purchases in multiples, such as multiples of six for a six-pack.
  4. Set the limits for each variation independently.
  5. Click Save Changes and Update.

Plugin behavior

When a customer tries to exceed the maximum or drop below the minimum, WooCommerce displays a notice on the cart page explaining the limit. The quantity input on the product page respects those minimum and maximum values directly, along with the step increment, so most customers never even hit the cart-page error because the input field already guides them toward a valid quantity.

Alternative plugins

Product Quantity for WooCommerce (free) sets minimum and maximum values per product, with a configurable step increment, though its variation-level support is limited in the free tier. Min Max Control (free) offers basic min/max rules that can be applied at the category level rather than just per product. WooCommerce Quantity Manager from Barn2 goes further, with role-based limits, category limits, and full per-variation controls in one plugin.

Method 3: Custom Code for Per-Variation Limits

If you want to skip a plugin for something this specific, 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;

    $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 to your theme’s functions.php or a site-specific plugin. It adds a “Max Quantity” field to each variation in the admin and checks the limit whenever a customer tries to add items to the cart, including checking what’s already sitting in the cart, not just the new quantity being added.

Notice the cart-quantity check in the validation function. This detail trips up a lot of DIY implementations: if you only validate the quantity being added in a single request, a customer can add the maximum three times in three separate add-to-cart clicks and end up with three times the intended limit. The snippet above sums the existing cart quantity with the new request before comparing against the cap, which closes that gap.

Real Store Scenarios

Limited edition sneaker drop

You’re selling a limited edition shoe in sizes US 7 through 13, with 50 pairs in stock per size. Setting maximum quantity to one per variation per order ensures fairness across buyers. Combined with WooCommerce’s native stock management, this stops any single customer from hoarding an entire size.

Wholesale t-shirt printing

You offer custom t-shirts across four sizes, from S up to XL. Wholesale customers need a minimum of twelve per size, a full dozen, while retail customers should be able to buy just one. Role-based quantity rules, available through WooCommerce Quantity Manager and similar plugins, apply different limits depending on the logged-in customer’s role rather than forcing every buyer through the same minimum.

Free samples alongside full-size products

You offer a “Sample” variation next to the full-size product. Set the sample variation’s minimum and maximum both to one, so it can neither be skipped nor bulk-ordered. Set the full-size variation’s minimum to one with no maximum, since there’s no reason to cap a paying customer’s order.

Comparing the Three Approaches

Built-in stock quantity costs nothing and takes five minutes to set up, but it only gives you a maximum, never a minimum, and that maximum is tied to physical inventory rather than a business rule you control independently. Once you sell out of a size, the “limit” disappears along with the stock, which isn’t the same as a deliberate purchase cap.

A dedicated plugin is worth the cost the moment you need a genuine minimum, a step increment, or role-based rules, none of which native WooCommerce stock fields can express. The official Min/Max Quantities extension handles the common cases cleanly. It’s the right default choice unless your rules get unusually specific, at which point a plugin like WooCommerce Quantity Manager, with its category and role logic, earns its higher price.

Custom code makes sense in a narrower set of cases: a single, well-defined rule (like the max-quantity example above) that doesn’t justify a whole plugin’s worth of settings screens and admin overhead, or a rule so specific to your business logic that no existing plugin expresses it cleanly. If you’re maintaining more than two or three custom snippets like this, that’s usually a sign it’s time to consolidate into a small custom plugin rather than scattering functions across your theme’s functions.php file.

How Quantity Limits Interact With Coupons and Discounts

A detail that catches store owners off guard: quantity limits and coupon rules don’t automatically know about each other. A percentage-off coupon applied to a cart that already hits its maximum quantity works fine, the discount calculates against whatever quantity made it past validation. But a “buy 3 get 1 free” style promotion built through a separate plugin can conflict with a variation’s maximum quantity if that maximum is lower than the quantity the promotion requires.

Before launching a promotion, add the promotional bundle to a test cart yourself and confirm it clears the quantity limit rather than silently failing at checkout. This is a five-minute check that saves a support queue full of confused customers on launch day.

Setting Limits for Digital and Service-Based Variations

Quantity limits aren’t only for physical inventory. A store selling digital licenses, one-time consulting slots, or service tiers as WooCommerce variations often needs a maximum of one per checkout for a specific service type, not because of stock, but because the underlying deliverable genuinely can’t be duplicated within a single order. A one-hour consulting slot variation, for instance, should almost always cap at one per order regardless of how many are technically “in stock,” since a customer buying five of the same hour-long session makes no operational sense.

The same min/max plugins covering physical variations work identically here, since WooCommerce treats a service-type variation the same as a physical one at the cart validation level. The logic doesn’t care what the SKU actually represents.

Troubleshooting

Quantity input not respecting limits on the product page

The HTML quantity field needs its min and max attributes set correctly, plus a step value, to actually enforce anything visually. Some themes override WooCommerce’s default quantity input template entirely. Check your theme’s woocommerce/global/quantity-input.php override, if one exists, and confirm it’s passing through the min_value and max_value arguments along with step rather than hardcoding its own values.

Limits applying to the parent product instead of specific variations

If a limit is landing on the whole product rather than an individual variation, the plugin you’re using may simply not support variation-level rules. Check the plugin’s documentation directly rather than assuming. The official WooCommerce Min/Max Quantities extension supports variation-level limits; a good number of free alternatives don’t, and will silently apply the limit at the product level instead.

Cart allows exceeding the limit when the same variation is added twice

The cart validation hook has to check existing cart quantities plus the new quantity together, not the new quantity in isolation. The code snippet earlier in this guide handles that correctly. If you’re relying on a plugin instead, confirm in its settings or documentation that it validates against existing cart contents rather than just the current add-to-cart request.

Min/max fields not appearing on variations at all

Confirm the plugin is actually active and that you’re viewing a variation, not the parent product’s general Inventory tab. Some plugins only add their fields after the variation has been saved once, so a brand-new, unsaved variation might not show the fields until after the first save.

Step increments producing an unexpected quantity in the cart

If a “Group of” or step setting is configured as 6 and a customer types 8 into the quantity field, most plugins will round the number up or down to the nearest valid multiple rather than rejecting it outright, and which direction it rounds depends on the specific plugin. Test this behavior directly rather than assuming, since a customer expecting to pay for 8 units and getting silently charged for 12 is the kind of surprise that generates a chargeback, not just a support ticket.

Best Practices

Display limits clearly on the product page itself. Customers shouldn’t discover a maximum only after reaching checkout, that’s a fast way to generate frustration and abandoned carts over what should be a minor detail. Set sensible defaults: a minimum of one and no maximum is the standard, and you should only restrict quantities when there’s an actual business reason behind it.

Test with your caching plugin active, not disabled. Page caching can serve stale quantity inputs after you change a limit, so exclude cart and checkout pages, and ideally single product pages with variations, from full-page caching. Consider user roles carefully: wholesale and retail customers frequently need different limits on the exact same variations, and treating them identically usually means one group ends up with rules that don’t fit them. Document your limits somewhere customers can find them before they add to cart, a shipping or FAQ page works fine, so nobody is surprised at the last step of checkout.

Frequently Asked Questions

Can I set a different maximum for the same variation depending on customer role?

Yes, but the built-in WooCommerce Min/Max Quantities extension doesn’t do this on its own. You’ll need a plugin that adds role-based logic, such as WooCommerce Quantity Manager, or a custom code snippet that checks wp_get_current_user() before applying the limit.

Do quantity limits work with backorders enabled?

They can conflict. If a variation allows backorders and also has a maximum quantity set, the maximum still applies as a hard cap regardless of stock status. A minimum quantity, on the other hand, has nothing to do with stock levels at all and applies whether the item is in stock, backordered, or on preorder.

What happens if stock quantity is lower than the configured maximum?

Stock quantity wins. WooCommerce won’t let a customer purchase more units than are physically in stock, even if a plugin’s maximum quantity setting technically allows a higher number. The two limits work independently, and whichever one is more restrictive at the moment of purchase takes effect.

Do I need to set limits on every variation, or just the ones that matter?

Just the ones that matter. Setting a maximum on every variation of a large catalog, including variations with no real stock or fraud risk, adds admin overhead for no benefit and increases the odds a limit gets set incorrectly somewhere and confuses a legitimate bulk buyer. Reserve limits for variations tied to a genuine business reason: limited stock, wholesale minimums, promotional caps, or one-off deliverables that can’t be duplicated.

Can minimum quantities be bypassed by adding items across multiple orders?

Yes, minimum quantity rules only apply within a single order or cart session. A customer determined to buy fewer than the wholesale minimum could technically place several small separate orders. If that’s a real concern, you’d need additional logic checking a customer’s order history, which goes beyond what quantity plugins typically offer out of the box.


How to Apply Multiple Shipping Classes to Variable Products in WooCommerce

Schema Markup for WooCommerce Products