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.

 

About the Company

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.

Share:

Share on facebook
Facebook
Share on twitter
Twitter
Share on pinterest
Pinterest
Share on linkedin
LinkedIn

Leave a Reply

On Key

Related Posts

How Effective are Cart Abandonment Emails

What Are Cart Abandonment Emails?

Cart abandonment emails are sent to customers who have previously added products to their cart but then failed to follow through to check out and