Clear cart data before adding new

Clear cart data before adding new

How to clear cart data before adding new item to the cart ?

Solution:

  1. Login to your wordpress backend.
  2. Go to apperance > Theme Editor > functions.php
  3. 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;
    } 
  4. Save it . It works fine with all versions of WordPress and woo-commerce plugin.

 

 

5 Comments

  1. Samantha says:

    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!!

  2. escort bayan says:

    Some state regulations are also stronger than others and NSW is recognized for obtaining incredibly tight regulations. Lotty Raimundo Morel

  3. erotik says:

    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

  4. 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

Leave a Reply

Your email address will not be published. Required fields are marked *