• Resolved Sarun developer

    (@saruncloudspring)


    I have a WordPress – Woocommerce Website.On my website i added empty cart button by using following code.

    `add_action( ‘init’, ‘woocommerce_clear_cart_url’ );
    function woocommerce_clear_cart_url() {
    global $woocommerce;
    if ( isset( $_GET[’empty-cart’] ) ) {
    echo “test”;
    //exit;
    $woocommerce->cart->empty_cart(true);
    }
    }
    add_action( ‘woocommerce_cart_actions’, ‘patricks_add_clear_cart_button’, 20 );
    function patricks_add_clear_cart_button() {
    echo “<a class=’button’ href=’?empty-cart=true’>” . __( ‘Empty Cart’, ‘woocommerce’ ) . “</a>”;
    } `

    This code is not working when user logged in.When user logged in apply the empty cart button then cart is not empty.This code only working at the time of user logged out.I am using latest version of woocommerce 3.2.2.

    I can’t understand how to fix.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support RK a11n

    (@riaanknoetze)

    I recommend getting in touch with the web developer community at https://stackoverflow.com/ or https://wordpress.stackexchange.com/ for feedback on any code that you’ve already written – the support forums here cater more with the default functioning of WooCommerce rather that customisation thereof.

    Alternatively, if you want, you could also take a closer at our Woo Experts at https://woocommerce.com/customizations/ that might be more familiar with the code and what you’re trying to achieve.

    I have the same problem.
    There are several snippets on the web to do this. All are basically the same and all stopped working a few weeks ago, including Booster Tools for Woocommerce.
    Did you find a solution to this?

    Hi, did either of you find out a fix for this?

    No, but I did find out that the Plugin for Follow-Up emails has something to do with it. Unfortunately I need both functions.

    I was having the same issue with Follow Up Emails / empty_cart(). I was also calling the function on the ‘init’ hook like the example above and it wasn’t working. I moved it to the ‘template_redirect’ hook and now it’s working! Can you try that and see if it works for you?

    Hi Simon,
    That worked! Thank you very much!!!!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Woocommerce Empty cart functions not working’ is closed to new replies.