We had a client recently that required a unique feature in WooCommerce. They have a category with several products and each of these products must be purchased in a separate order and cannot be combined with other categories.
Here’s a breakdown of what needed to happen:
- If a user has a product in their cart from category A, nothing else can be in the cart including category A and an error message displayed.
- If a user has product(s) in their cart from a category B or Category C, and adds an items from Category A, the cart needs to clear and an error message displayed.
This would be similar to the “purchase individually” button in WooCommerce but without the quantity restriction. Using WooCommerce 5+ you can use the following code to accomplish this:
Add the following to your functions.php or create a custom plugin.Â
Change CATEGORYSLUG to the slug of the category you want the restriction set for.