only allow single item in Woocommerce cart by using filter woocommerce_add_to_cart_validation -
if want restrict customer add single item in woocommerce cart , can use filter "woocommerce_add_to_cart_validation".
the filter defined in following location(s). /includes/class-wc-ajax.php
// add single item in woocommerce cart
add_filter( 'woocommerce_add_to_cart_validation', 'restrict_only_one_item_in_cart' ); function restrict_only_one_item_in_cart($cart_item_data) { global $woocommerce; $item_count = $woocommerce->cart->cart_contents_count; if($item_count > 0){ wc_add_notice( 'sorry. 1 item allowed. if add another, please remove item in cart.', 'error' ); return false; } return $cart_item_data; }
Comments
Post a Comment