Use the WooCommerce REST API to read and update product and variation quantity rules added by Min/Max Quantities.
Note:
This is a Developer level doc. If you are unfamiliar working with code and resolving potential conflicts, we recommend you work with a Woo Agency Partner for larger projects, or find a WooCommerce developer on Codeable for smaller customizations. We are unable to provide support for customizations under our Support Policy.
Replace the example store URL, product IDs, and API credentials with your own. Use HTTPS and a REST API key with read and write permissions. See the REST API authentication guide.
REST API
↑ Back to topThese examples use the WooCommerce REST API v3 endpoints.
Min/Max Quantities extends the /products/ and /variations/ endpoint responses with new properties related to quantity rules.
Products
↑ Back to topProduct properties
group_of_quantity—integer;readwrite. Require products to be purchased in multiples of this value.min_quantity—integer;readwrite. Minimum required product quantity.max_quantity—integerstring;readwrite. Maximum allowed product quantity.exclude_order_quantity_value_rules—string;readwrite. Exclude product from order quantity and value rules.exclude_category_quantity_rules—string;readwrite. Exclude product from category quantity rules.combine_variations—string;readwrite. Enable 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"
}'
Replace 12 with the simple product ID.
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"
}'
Replace 14 with the variable product ID.
Error codes
When updating quantity rules for a product, here are some errors that you might get in the response:
woocommerce_rest_invalid_product_type_allow_combinations— This error is triggered when trying to set thecombine_variationskey on a product that is not a Variable product.woocommerce_rest_invalid_min_quantity— This error is triggered when trying to set amin_quantitythat is either greater than the Max Quantity or not a multiple of the Group of value.woocommerce_rest_invalid_max_quantity— This error is triggered when trying to set amax_quantitythat is not a multiple of the Group of value.
Variations
↑ Back to topVariation properties
variation_quantity_rules—string;readwrite. Enable this option to set quantity rules for a specific variation.group_of_quantity—integer;readwrite. Require products to be purchased in multiples of this value.min_quantity—integer;readwrite. Minimum required product quantity.max_quantity—integerstring;readwrite. Maximum allowed product quantity.exclude_order_quantity_value_rules—string;readwrite. Exclude product from order quantity and value rules.exclude_category_quantity_rules—string;readwrite. Exclude 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"
}'
Replace 14 with the variable product ID and 15 with the variation ID.
Error codes
When updating quantity rules for a variation, here are some errors that you might get in the response:
woocommerce_rest_invalid_product_type_allow_combinations— This error is triggered when trying to set thecombine_variationskey on a variation. This key can only be set on Variable products.woocommerce_rest_invalid_variation_min_quantity— This error is triggered when trying to set amin_quantitythat is either greater than the Max Quantity or not a multiple of the ‘Group of’ value.woocommerce_rest_invalid_variation_max_quantity— This error is triggered when trying to set amax_quantitythat is not a multiple of the Group of value.
For setting up rules in the dashboard, see Min/Max Quantities.
Questions and support
↑ Back to topSomething missing from this documentation? Still have questions and need assistance?
- If you have a question about a specific extension or theme you’d like to purchase, contact us to get answers.
- If you already purchased this product and need some assistance, get in touch with a Happiness Engineer via our support page and select this product’s name from the Product dropdown.