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:

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
Contribute to Improving This Blog
Did you enjoy this article? Was it helpful? Contribute to help me writing more articles! The funds collected from this blog are reinvested directly into improving my skills or the blog so that I can provide more and better content!
Make a one-time donation
Make a monthly donation
Make a yearly donation
Choose an amount
Or enter a custom amount
Your contribution is appreciated.
Your contribution is appreciated.
Your contribution is appreciated.
DonateDonate monthlyDonate yearlyLeave a Reply
Want to join the discussion?Feel free to contribute!
hi in this condition i need to add redirect link
From what i noticed in the code above, you can limit the order by selecting product id. What if you have so many products and you want to limit all the products purchase to be per order (individually).
This is helpful definitely, moreover I am looking for something which can only allow adding one product in cart and no other products in the cart. Is this possible?
This codes only works one way.
So if i have an item in the cart, say item “ID230”. Then i try add the item “ID31” (as in example) the error message shows.
But if i have item “ID31” in my cart already then i add other items, it allows me to do so.
The array is not working for me, when i implement the code it just blankets 1 product per order
How does this work on Multisite where it has to apply only to a single site store?
Hi, can this be possible for categories instead of product IDs? Limit purchase to one product per order when the product is in a specific category? What I wanna see is the qty field not showing on the product page and on the cart page. Thanks for this, this is really helpful!
Hello there,
Technically yes, it is possible. You have the product ID, so you can check what categories it belongs to with `wp_get_post_categories` (https://developer.wordpress.org/reference/functions/wp_get_post_categories/) and then change the conditions to work on the category instead of the ID.
Hi!
Great post. It worked perfect.
Is it possible to limit the purchase but without activating the error message?
Thank you!
Hello,
Not that I can think of. The error message can be removed but it needs further custom code or template edits.
Great code. Well done!
Thank you!