How to: Force products in category to be purchased individually

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.

 

368 Durham is a Website Design Company in Oshawa, Ontario. Our experts have years of experience in Website Design, Social Media Management and Search Engine Optimization. If you are looking for a Web Designer Oshawa, contact us today!

Share:

Facebook
Twitter
Pinterest
LinkedIn

Leave a Reply

On Key

Related Posts