Put it in your theme’s functions.php.

Whenever your visiot will try to add a product twice mistakenly, it will keep only 1 of this product in his cart.

However, he will be still able to change the quantity of the single product he has in cart.

// disable double add to cart of a product
add_filter('woocommerce_add_to_cart_validation', 'my_validation_handler', 10, 2);
function my_validation_handler($is_valid, $product_id) {
    foreach(WC()->cart->get_cart() as $cart_item_key => $values) {
        if ($values['data']->id == $product_id) {
            return false;
    return $is_valid;

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?