It’s not unusual that products need to be handled singularly in an order, or that they can’t be sold in more than one unit.

WooCommerce covers the second case so you can limit customers to buy only one unit of a specific item per order. The first case instead is not covered by default, but it’s still possible to handle it with some custom coding.

Let’s see how to do both.



Limit purchases to one product per order

This scenario is not covered by WooCommerce by default, but it can be done with custom code. The goal is to allow customers to buy only one product per order.

Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:

This snippet will not allow customers to add more than one item to the cart, showing them an error message and forcing them to empty the cart to order or to complete the current order first.

To choose which product to limit you need to change the product ID on line 3 of this snippet. In the example, the ID is 31. If you need to limit multiple products, change line 3 with this code instead:

if ( in_array( $product_id, array( 31, 32, 33 ) ) ) {

Limit purchases to one item per order

This is the second scenario and it covers any case where you don’t want your customers to add more units of the same product to the cart, but still allow them to buy multiple different products to the cart.

As I said before, this is already covered by WooCommerce, and to do it you need to edit a product in Products > All Products and click on the Inventory tab, then select the option Sold Individually, like shown in this screenshot:

Inventory tab on the Edit Product screen, showing the Sold Individually option.

After selecting this option, customers will not be able to buy more than one of the item in the same order, but they still can do it in different orders.

Also, if you are you looking for how to limit purchases by
role I wrote about that in this article!

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.