How to Allow One Item in Cart?
-
Hello Team,
After doing some google and research I found below code which allows only one item to be book at a time.
/* Clear cart data before adding new */ // before addto cart, only allow 1 item in a cart add_filter( 'woocommerce_add_to_cart_validation', 'woo_custom_add_to_cart_before' ); function woo_custom_add_to_cart_before( $cart_item_data ) { global $woocommerce; $woocommerce->cart->empty_cart(); // Do nothing with the data and return return true; }
I want some functionality when user click on Add to Cart button it’ll clear there previous cart data completely and add new cart data, only allow one product purchase at a time.
I have used above code but it’s working sometime and sometime it’s not working.
i.e. If I am login as a admin then I can see multiple product in cart, sometime it’s also doing weird thing on refresh page it’s adding product automatically.
Can you please help me how I can forcefully clear cart every time when someone click on add to cart button and add new data whatever they have requested?
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘How to Allow One Item in Cart?’ is closed to new replies.