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

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -