Quantity Limits by User Role in WooCommerce
Apply quantity limits by user role in WooCommerce: wholesale minimums, retail maximums, per-role step increments and validation for logged-out visitors.

A store selling to both trade and public has two opposite problems in one catalogue. The trade buyer must not order three units; the retail buyer must not clear the shelf of a limited line. Both are quantity rules, and both depend on who is logged in.
Model the roles before the rules
Start with the roles you already use — `customer`, `wholesale`, perhaps `distributor` — and write the intent for each:
- Retail customer: maximum per line, occasionally a maximum per order for scarce stock.
- Wholesale: minimum per line and a step matching case size.
- Distributor: larger minimum, larger step, no maximum.
Rules that cannot be expressed in that table usually belong somewhere else — a pre-order flow, or a quote request — rather than in quantity settings.
Resolving the role in one place
The product page and the cart must agree, so resolve the applicable rule through a single function:
```php function df_quantity_rule_for_user( $product_id ) { $user = wp_get_current_user(); $roles = (array) $user->roles;
foreach ( [ 'distributor', 'wholesale', 'customer' ] as $role ) { if ( in_array( $role, $roles, true ) ) { return df_rule( $product_id, $role ); } } return df_rule( $product_id, 'guest' ); } ```
Call it from `woocommerce_quantity_input_args` for the input, and again in `woocommerce_check_cart_items` for validation. Two separate implementations of the same priority order will drift within a month.
Maximums need a definition of "per"
"Maximum 2" is ambiguous. Per line, per order, or per customer ever? The first two are cart-side checks. The third requires reading the customer's order history and excluding cancelled and refunded orders, and it only functions for logged-in accounts — which is a reason to require login for limited lines rather than to trust a guest checkout.
Pair limits with role-based pricing
Quantity rules and pricing rules answer the same question from different angles, and customers experience them as one thing. A wholesale minimum of 12 with a tier price starting at 12 feels deliberate; a minimum of 12 with a tier starting at 10 looks broken. Set them together and review them together — see role-based pricing for B2B stores.
Doing it as configuration
Min & Max Quantities for WooCommerce applies minimums, maximums and step increments per user role as well as per product and category, with a documented precedence order and cart-side validation. Combined with Wholesale & Role-Based Pricing, one catalogue can serve retail and trade without a second store.
Also worth reading: minimum quantity by category for range-wide rules.
Test as each role, not as admin
Administrators frequently bypass rules by accident, which is why role logic looks perfect in the back office and fails for real buyers. Create one test account per role, keep them, and place a real order with each after any change to the rules.
FAQ
- How do I set different quantity limits for wholesale and retail customers?
- Attach the minimum, maximum and step to the user role, resolve the current customer's role at cart validation, and fall back to a default rule for logged-out visitors.
- Which role applies when a customer has more than one?
- Pick a documented priority order — usually the most permissive commercial role wins — and resolve it in one place so the product page and the cart never disagree.
- Can I limit how many units one customer buys in total?
- Yes, but that is a purchase-history limit rather than a cart limit. It needs a lookup of past orders for the account, so it only works for logged-in customers.
- What quantity rules apply to guests?
- Guests get the default rule. If your wholesale terms should not be visible at all, combine the role rules with hidden prices so guests never see trade quantities or trade pricing.
- Do role-based limits work with coupons and bulk pricing?
- They should be evaluated before pricing so a customer never sees a tier price for a quantity the rules forbid. Validate quantities first, then apply role-based pricing.
This article is part of our WooCommerce quantity rules topic hub, where the related plugins and guides live together.


