woocommerce: don’t want increment item quantity after ‘addtocart’ click if item exist in the cart

Hi can you recommend me some woocommerce plugin(maybe I don’t need plugin and it’s matter of right setting) for this use case:
I don’t want to increment quantity of the product if product exist in the cart.
User can increment quantity of product in the cart

Related posts

2 comments

  1. Please try this hook into your function.php file

    add_filter( 'woocommerce_is_sold_individually', '__return_true' );
    
  2. The best way to solve this would be to hook into the woocommerce_add_to_cart_validation action hook. You could do something like this (not tested):

    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;
    }
    
    add_filter('woocommerce_add_to_cart_validation', 'my_validation_handler', 10, 2);
    

    This will basically skip adding product to cart if it already exists there.

    Just keep in mind that if you sell advanced configurable products, you may wish to add additional checks besides just comparing product IDs.

Comments are closed.