This code enables you to force a set amount of variations or a set quantity of products per taxonomy term are added to cart before checkout is available.
For simple products, the code works like this :
You set a fixed quantity in the code along with 1 or more categories and a notice will display like this if the quantity matches or doesn’t match.
In this example, you customers can only checkout once the fixed quantity matches your code settings.
For variable products, the code works like this :
You set a fixed number of variations based on a product id and a notice displays when the amount of variations match allowing your customer to proceed to checkout otherwise another notice shows forcing the set amount of variations to be adjusted in the cart like you see in the following images :
In this case, your customer can only proceed to the checkout once 5 chocolate variations to make up 1 box have been added to the cart.
Copy and paste the PHP code to the end of your child themes functions file or custom functionality/code snippets plugin.
- For variations, set the variable product id on line 11 and the quantity on line 13.
- For simple products, set the category or array of categories on line 49 and the quantity on line 51.
The code can be used with any taxonomy terms including product categories and tags.