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.

 

 

16 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

  5. Dann says:

    Hello there! I could have sworn I’ve visited this site before but after browsing through
    many of the articles I realized it’s new to me.
    Anyways, I’m definitely pleased I found it and
    I’ll be bookmarking it and checking back regularly!

  6. Gia says:

    Your way of explaining all in this paragraph is in fact fastidious, every one be capable of easily
    be aware of it, Thanks a lot.

  7. Chang says:

    Attractive component to content. I simply stumbled upon your blog and in accession capital to claim that I acquire in fact loved account your weblog posts.
    Anyway I’ll be subscribing in your augment and even I achievement
    you get entry to consistently rapidly.

  8. I have been absent for a while, but now I remember why I used to love this site. Thanks , I will try and check back more frequently. How frequently you update your site?

  9. Your house is valueble for me. Thanks!…

  10. Terrific work! This is the type of information that should be shared around the web. Shame on Google for not positioning this post higher! Come on over and visit my website . Thanks =)

  11. very nice post, i certainly love this website, keep on it

  12. Would you be interested in exchanging links?

  13. very nice post, i certainly love this website, keep on it

  14. Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I?d prefer to use some with the content on my blog whether you don?t mind. Natually I?ll give you a link on your web blog. Thanks for sharing.

  15. Amazing blog! Do you have any suggestions for aspiring writers? I’m planning to start my own site soon but I’m a little lost on everything. Would you propose starting with a free platform like WordPress or go for a paid option? There are so many options out there that I’m totally overwhelmed .. Any suggestions? Thanks!

Leave a Reply

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

eight  ×    =  seventy two