WordPress.org

Ready to get started?Download WordPress

Forums

WooCommerce - excelling eCommerce
[resolved] A button to empty the chart !? (8 posts)

  1. Elan42.com
    Member
    Posted 1 year ago #

    Hi ! Sorry to bother, I searched > 1 hour but I only find "empty chart" bug stuff.

    WooCommerce works great, but how can I create a button to "empty the chart" with one click ?
    This is very important for me because I'm jumping from "buy button" to "checkout" directly and some people often have their chart dirty from previous sessions.

    http://wordpress.org/extend/plugins/woocommerce/

  2. bheadrick
    Member
    Posted 1 year ago #

    do you have "clear cart when logging out" checked?

    not sure how that would impact users who are not already logged in...

  3. Elan42.com
    Member
    Posted 1 year ago #

    Yes I have this this option turned on.

    But I don't use user registration (I make user compile the form + pay as guests). So how chart will work ?

    Will it only be in the php session and so will endure 1-2 minutes ?
    However, I would like an "empty chart" option for users that make some mistakes.

    As you can see, I made some code customizations to go from the "item button" directly to "checkout button", so I don't have the cart page:

    http://www.eurojob.co.uk/booking-2/

  4. Gerhard
    Member
    Posted 1 year ago #

    Add the following code to your theme's functions.php file and then just append ?clear-cart to any of your site urls

    // check for clear-cart get param to clear the cart
    add_action( 'init', 'woocommerce_clear_cart_url' );
    function woocommerce_clear_cart_url() {
    	if ( isset( $_GET['clear-cart'] ) ) {
    		global $woocommerce;
    		$woocommerce->cart->empty_cart();
    	}
    }
  5. Elan42.com
    Member
    Posted 1 year ago #

    thanks !

  6. Robslyn88
    Member
    Posted 1 year ago #

    Hi Thanks for the help,

    what do you mean by

    and then just append ?clear-cart to any of your site urls?

    sorry i am new to wordpress and trying to add a clear cart button to my woocomerce plugin.

    (My site is not live yet so can not send a link)

  7. idealneal
    Member
    Posted 1 year ago #

    I am having the same issue. I have added the code to the functions file and I have added this code to the cart page but nothing seems to be happening. Anybody know what is wrong?

    <input type="submit" class="button" name="clear-cart" value="<?php _e('Empty Cart', 'woocommerce'); ?>" />

  8. Sebastien D
    Member
    Posted 1 year ago #

    This is what I need for my Auction plugin.

    Try using this.

    <form method="get" action="?clear-cart">
    <input type="submit" class="button" name="clear-cart" value="<?php _e('Empty Cart', 'woocommerce'); ?>" />
    </form>

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic