Min/Max Quantities

Min/Max Quantities makes it possible to:

  • Define minimum and maximum quantity limits per product/variation, or per order.
  • Require specific products, or product categories, to be purchased in predefined multiples.

Installation

↑ Back to top
  1. Download the .zip file from your WooCommerce account.
  2. Go to WordPress Admin > Plugins > Add New.
  3. Click Upload Plugin at the top.
  4. Choose File and select the .zip file you downloaded in Step 1.
  5. Click Install Now and Activate the extension.

Important: Min/Max Quantities requires WooCommerce 8.2+, PHP 7.4+ and WordPress 6.2+.

Configuration

↑ Back to top

Product Rules

↑ Back to top

To configure quantity rules for a product:

  1. Edit the product.
  2. Navigate to the Product Data > General tab.
  3. Locate the Quantity Rules section.
  4. Configure the Minimum Quantity, Maximum Quantity, Group of and Exclude from options.
Editing product quantity rules.

Minimum quantity — Minimum required quantity for this product per order.
Maximum quantity — Maximum allowed quantity for this product per order.
Group of — Enter a quantity to require this product to be purchased in multiples.

If you have defined order and category rules, you can tick the Exclude from checkboxes to skip individual products when evaluating order and category rules:

Exclude from: Order rules — Exclude this product from order quantity and order value rules.
Exclude from: Category rules — Exclude from category Group of rules. Automatically enabled when a a Group of rule is set for a product.

When a Group of rule is set for a product, then category Group of rules do not apply to this product.

Variable Products

When editing a Variable product, an additional option appears under Product Data > General > Quantity Rules called Combine Variations.

  • When this option is disabled, each variation will inherit the rules you have defined in the Quantity Rules section.
  • When this option is enabled, the specified quantity rules are applied in the cart to all variations of this product.

For example, if a Maximum quantity of 5 has been set on the parent and Combine Variations is disabled, you must purchase at least 5 units of each individual variation. If Combine Variations is enabled, it is possible to satisfy the rule by adding 2 units of a variation and 3 units of another.

Variation Rules

When Combine Variations is disabled, it is possible to define a different set of quantity rules for individual variations:

  1. Navigate to Product Data > Variations.
  2. Locate the variation you need to edit and expand its settings.
  3. Tick the Quantity rules box.
  4. Edit the Minimum quantity, Maximum quantity, Group of and Exclude from fields.
  5. Save your changes.

When Combine Variations is enabled, the rules you have specified will be validated in the cart/checkout pages only.

Order Rules

↑ Back to top

In addition to product-level rules, the extension allows you to set up minimum and maximum Order quantity and Order value rules under WooCommerce > Settings > Products > General:

Setting up order rules.

Minimum Order Quantity — The minimum number of items required in an order.
Maximum Order Quantity — The maximum number of items allowed in an order.
Minimum Order Value — Minimum required order value, in your store’s base currency.
Maximum Order Value — Maximum allowed order value, in your store’s base currency.

It is possible to exclude individual products from order quantity and value rules.

Category Rules

↑ Back to top

The extension allows you to set Group of quantity rules for entire categories of products. Category-level rules are inherited by all products in the category, except for those with a product-level Group of rule. To create a Group of category rule:

  1. Navigate to Products > Categories.
  2. Locate and edit a category.
  3. Enter a Group of value to require customers to purchase products from this category in multiples.
  4. Save.

Developer Resources

↑ Back to top

This section is written for WooCommerce developers looking to extend or customize WooCommerce Min/Max Quantities. It requires an advanced understanding of PHP and WordPress development.

REST API

↑ Back to top

WooCommerce 2.6 added support for REST API endpoints based on the WordPress REST API infrastructure.

Min/Max Quantities extends the /products/ and /variations/ endpoint responses with new properties related to quantity rules.

Products

Product properties

AttributeTypeContextDescription
group_of_quantityintegerread writeRequire products to be purchased in multiples of this value.
min_quantityintegerread writeMinimum required product quantity.
max_quantityinteger stringread writeMaximum allowed product quantity.
exclude_order_quantity_value_rulesstringread writeExclude product from order quantity and value rules.
exclude_category_quantity_rulesstringread writeExclude product from category quantity rules.
combine_variationsstringread writeEnable this option to combine the quantities of all purchased variations when checking quantity rules.

Note: Available only for Variable Products.
Example: Update quantity rules for a Simple Product
curl -X PUT https://example.com/wp-json/wc/v3/products/12 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
        "group_of_quantity": 2,
        "min_quantity": 4,
        "max_quantity": 8,
        "exclude_order_quantity_value_rules": "no",
        "exclude_category_quantity_rules": "yes",
}'

where 12 is the ID of the Simple Product.

Example: Update quantity rules for a Variable Product

curl -X PUT https://example.com/wp-json/wc/v3/products/14 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
        "group_of_quantity": 2,
        "min_quantity": 4,
        "max_quantity": "",
        "exclude_order_quantity_value_rules": "no",
        "exclude_category_quantity_rules": "yes",
        "combine_variations": "no",
}'

where 14 is the ID of the Variable Product.

Error codes

When updating quantity rules for a product, here are some errors that you might get in the response:

Error codeDescription
woocommerce_rest_invalid_product_type_allow_combinationsThis error is triggered when trying to set the combine_variations key on a product that is not a Variable Product.
woocommerce_rest_invalid_min_quantityThis error is triggered when trying to set a min_quantity that is either greater than the ‘Max Quantity’ or not a multiple of the ‘Group of’ value.
woocommerce_rest_invalid_max_quantityThis error is triggered when trying to set a max_quantity that not a multiple of the ‘Group of’ value.

Variations

Variation properties

AttributeTypeContextDescription
variation_quantity_rulesstringread writeEnable this option to set quantity rules for a specific variation.
group_of_quantityintegerread writeRequire products to be purchased in multiples of this value.
min_quantityintegerread writeMinimum required product quantity.
max_quantityinteger stringread writeMaximum allowed product quantity.
exclude_order_quantity_value_rulesstringread writeExclude product from order quantity and value rules.
exclude_category_quantity_rulesstringread writeExclude product from category quantity rules.

Example: Update quantity rules for a variation

curl -X PUT https://example.com/wp-json/wc/v3/products/14/variations/15 \
    -u consumer_key:consumer_secret \
    -H "Content-Type: application/json" \
    -d '{
        "variation_quantity_rules": "yes",
        "group_of_quantity": 3,
        "min_quantity": 3,
        "max_quantity": 12,
        "exclude_order_quantity_value_rules": "no",
        "exclude_category_quantity_rules": "yes",
}'

where 14 is the ID of the Variable Product and 15 is the ID of the variation.

Error codes

When updating quantity rules for a variation, here are some errors that you might get in the response:

Error codeDescription
woocommerce_rest_invalid_product_type_allow_combinationsThis error is triggered when trying to set the combine_variations key on a variation. This key can only be set on Variable Products.
woocommerce_rest_invalid_variation_min_quantityThis error is triggered when trying to set a min_quantity that is either greater than the ‘Max Quantity’ or not a multiple of the ‘Group of’ value.
woocommerce_rest_invalid_variation_max_quantityThis error is triggered when trying to set a max_quantity that not a multiple of the ‘Group of’ value.

Snippets

↑ Back to top

Is it possible to prevent the quantity and price of a product from being counted towards Order quantity and value rules?

To ignore the quantity/price of a cart item when checking the Order quantity and value rules, it is necessary to use the following snippet:

<?php
/**
 * Plugin Name: WooCommerce Min/Max Quantities - Do not count product quantity/value in Order quantity/value rules.
 * Plugin URI: https://woocommerce.com/products/minmax-quantities/
 * Description: Use this plugin to ignore the quantity/price of a product when checking the Order quantity/value rules.
 * Version: 1.0
 * Author: WooCommerce
 * Author URI: https://woocommerce.com/
 * Developer: Jason Kytros
 *
 * Requires at least: 3.9.0
 * Tested up to: 6.9.0
 *
 * Copyright: © 2022 Automattic.
 * License: GNU General Public License v3.0
 * License URI: http://www.gnu.org/licenses/gpl-3.0.html
 */
 
add_filter( 'wc_min_max_quantity_minmax_do_not_count', 'mmq_order_rules_do_not_count', 10, 4 );

function mmq_order_rules_do_not_count( $result, $checking_id, $cart_item_key, $values ) {

        // Replace '123' and '456' with the specific product IDs.
	if ( in_array( $checking_id, array( 123, 456 ) ) ) {
		$result = 'yes';
	}
 	return $result;
}
View on Github

FAQ

↑ Back to top

Is it possible to import/export Min/Max Quantities rules?

It is only possible to export and import product level rules, by using the built-in Import/Export tool. Before generating your CSV file, please ensure that Export Custom Meta? is checked.

When importing modified data, make sure that the values in the following columns are edited correctly:

Column Header Title(Value) & Description
Meta: minimum_allowed_quantity(Int) Sets a minimum allowed quantity for purchase for the product
Meta: maximum_allowed_quantity(Int) Sets a maximum allowed quantity for purchase for the product
Meta: group_of_quantity(Int) Sets the ‘Group of’ quantity rule at the product level
Meta: minmax_cart_exclude(yes/no) Exclude this product from order rules (minimum/maximum quantity and value).
Meta: minmax_category_group_of_exclude(yes/no) Exclude this product from category ‘Group of’ quantity rules. Note: If a product-level ‘Group of’ quantity rule is defined, then the product is automatically excluded from category ‘Group of’ rules.
Deprecated
Meta: minmax_do_not_count
(yes/no) Deprecated
To prevent the quantity or price of products/variations from being counted towards Minimum/Maximum order quantity/value rules, it is necessary to use the wc_min_max_quantity_minmax_do_not_count filter. (Snippet above)

Questions and Feedback

↑ Back to top

Have a question before purchasing? Please fill out this pre-sales form.
Already purchased and need some assistance? Get in touch with a Happiness Engineer.

Use of your personal data
We and our partners process your personal data (such as browsing data, IP Addresses, cookie information, and other unique identifiers) based on your consent and/or our legitimate interest to optimize our website, marketing activities, and your user experience.