Disable double add to cart of a product
If you want to disable multiple or double add to cart quantity for woocommerce product , then you can add the following code on the function.php file.
// 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;
}