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:

add_filter( 'woocommerce_add_to_cart_validation', 'wc_limit_one_per_order', 10, 2 );
function wc_limit_one_per_order( $passed_validation, $product_id ) {
if ( 31 !== $product_id ) {
return $passed_validation;
if ( WC()->cart->get_cart_contents_count() >= 1 ) {
wc_add_notice( __( 'This product cannot be purchased with other products. Please, empty your cart first and then add it again.', 'woocommerce' ), 'error' );
return false;
return $passed_validation;
view raw functions.php hosted with ❤ by GitHub

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!

12 replies
  1. Ben
    Ben says:

    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).

  2. Dhirendra
    Dhirendra says:

    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?

  3. Dale
    Dale says:

    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.

  4. bruceandmrgiggles
    bruceandmrgiggles says:

    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!

  5. Diego
    Diego says:

    Great post. It worked perfect.
    Is it possible to limit the purchase but without activating the error message?
    Thank you!


Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply