How to clear cart data before adding new item to the cart ?
Solution:
- Login to your wordpress backend.
- Go to apperance > Theme Editor > functions.php
- Add the following code/* 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;
}
- Save it . It works fine with all versions of WordPress and woo-commerce plugin.
5 Comments
Hello, i believe that i saw you visited my web site thus i came to go back the favor?.I’m attempting to find
issues to enhance my website!I assume its adequate to make use of some of your ideas!!
Some state regulations are also stronger than others and NSW is recognized for obtaining incredibly tight regulations. Lotty Raimundo Morel
Prepared do an dissuade be so whatever steepest. Yet her beyond looked either day wished nay. By doubtful disposed do juvenile an. Gwyneth Tobie Aloysius
Awesome write-up. I am a regular visitor of your site and appreciate you taking the time to maintain the excellent site. I will be a regular visitor for a long time. Magdalene Pavel Ackerley
mhwgGsdanYWry