Validate woocommerce cart depending on shop archive page
-
Is it possible to validate the woocommerce cart with
woocommerce_add_to_cart_validation
based on the unique shop archive page the user is currently on? I am adding to the cart via ajax.e.g.
IF user is on Page strongshop AND max item count is 20…apply rule.
IF user is on Page smallshop AND max item count is 10….apply rule.Below code works when the is_page constraints are removed:
// remove the redirect add_filter( 'woocommerce_cart_redirect_after_error', '__return_false'); add_action( '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((is_page('strongshop') || is_page('strongshopmobile')) && $item_count >= 20){ return false; } return $cart_item_data; }
Viewing 6 replies - 1 through 6 (of 6 total)
Viewing 6 replies - 1 through 6 (of 6 total)
- The topic ‘Validate woocommerce cart depending on shop archive page’ is closed to new replies.