My client has asked for the ability to offer free samples of their variable products on their Woocommerce online store, with a maximum of 1 of each unique product sample and 5 of any of the samples on their order.
I’ve achieved part of this by adding an extra “Free Sample” variation to each product and then using a free Min/Max quantity plugin to limit the amount of each individual free sample to 1 per order, please see the following screenshots:
https://ibb.co/f0Wd7XC
https://ibb.co/8DrsZZj
So far I haven’t established a way to limit the maximum number of any combination of the “Free Sample” variations to 5 though. The only way I can see is by limiting the total number of free products (i.e. price = £0) per order to 5, or alternatively by assigning a specific shipping class to each variation (i.e.”Free Samples”) and then somehow limiting the amount of products assigned with this shipping class in each order to 5. Is this possible?
Cheers,
M.
2
Answers
Woocommerce have validation hook which you can use.
First one is when we add to our cart
Second one is when we update the cart on cart page for example.
In $cart_item you can debug and see all info for the current product in the cart. From there you can add condition depending on shipping or attribue or price or w/e you want.
This is what you are looking for (NO PLUGIN NEEDED):
In the theme’s function.php add the following:
Credit goes to 7uc1f3r for the solution on: Force minimum order quantity for specific products including variations on WooCommerce cart page
I only added and changed some code to fit it for the maximum bundle. This works for free samples stuff and you can also use it for any product the shop owner wants to limit to a set amount of bundle, as this isn’t hardcoding the limit to a certain product.
Here is an example of this working: