How to Limit Customer Buy One Product Only with WooCommerce

How to Limit Buying One Item Only in WooCommerce

I have started using WooCommerce since year 2012 and i like it because it provides me many customized options to suit my needs or client requirement.

Case Study:One of the possible situation is where i need to disable the shopping cart. In this way, the customer only can buy one item, if the customer goes to another product and tries to buy it, the cart will be cleaned and the last item added.



Open your theme functions.php, and put below code at the end.

add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );

function woo_custom_add_to_cart( $cart_item_data ) {
global $woocommerce;

return $cart_item_data;

Finally, save the file. And now you can test by adding new product to your existing cart with items, see whether it will added the latest product only and remove all previous products in the cart.


Share this:


  1. Hello terry,
    I need the same thing but only for a specific product.
    For example i have n products A,B,C …W
    You can buy A to W in all the quantité you want and you can mixte them but the product Z can only be sale alone.

    I don”t find a solution.

    Do you think you could help me ?

    I am not very kind with code.

    Many thanks



  2. Hi! I tried your code but surprisingly it didnt work. In the site I’m working on, the product is being added thru an A link using the url param “?add-to-cart=999″. May that be the cause? Looks like the filter you posted here cannot intercept the mentioned url param.
    Any ideas?

Leave a Comment.