I am creating eCommerce portal in wordpress using woocommerce.I have certain condition for products to be added in cart category wise.
I want to add condition if (category 1) then add only 2 items in cart or if(category 2) then add only 3 items in cart etc…
Here I am using
// Validate add to cart
function add_the_limited_items_validation( $passed ) {
if ( $quantity>2 )) {
wc_add_notice( __( 'You are not allowed to add more than 2 product for category..', 'woocommerce' ), 'error' );
$passed = false;
}
return $passed;
}
add_action( 'woocommerce_add_to_cart_validation','add_the_limited_items_validation', 10, 5 );
Here, I am not able to add condition category wise.Please help and suggest for same.Thanks