• Hi,

    I have a WordPress site with a Woocommerce shop. I would like that the cart gets emptied everytime a new page (product) loads, except of course if you are proceding to do the Check-out. Does anyone know how can I achieve this? Maybe by adding some funtion to the functions.php
    Thanks in advance for your help.
    Best regards,

    Freddie.

    https://www.ads-software.com/plugins/woocommerce/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @fedestura, i believe what you try to achieve is the customer only can buy one item, if the customer goes to another product and tries to buy it, the cart will be cleaned and the last item added, right?

    If yes, you can put below code into our theme functions.php:

    add_filter( 'woocommerce_add_cart_item_data', 'woo_custom_add_to_cart' );
    
    function woo_custom_add_to_cart( $cart_item_data ) {
    global $woocommerce;
    $woocommerce->cart->empty_cart();
    
    return $cart_item_data;
    }

    Thread Starter fedestura

    (@fedestura)

    Hi @Terrysang,

    That’s exactly what we are trying to achieve. I have placed the code that you tell me and it doesn’t seem to work. I added it to Theme functions (functions.php). When a person tries to click on another product it says they have to empty the cart. This is our website: https://www.retreatdiscounter.com/
    Thanks in advance for your help.
    Cheers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to empty cart on load on WooCommerce’ is closed to new replies.