WordPress.org

Support

Support » Plugins and Hacks » Add an empty cart button to cart page

Add an empty cart button to cart page

  • I want to add a clear cart button next to the update cart button on the cart page.
    I added this code to the functions file:

    // 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();
    }
    }

    and I added this code to cart.php just before the update button:

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

    Nothing shows up. Obviously I have done something wrong. I know just enough PHP to be dangerous. If anyone could help I sure would appreciate it.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Together with the following Empty Cart button code in cart.php:

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

    try adding this to your functions.php file instead, which checks for both GET and POST form submissions:

    add_action('init', 'woocommerce_clear_cart_url');
    function woocommerce_clear_cart_url() {
    	global $woocommerce;
    	if( isset($_REQUEST['clear-cart']) ) {
    		$woocommerce->cart->empty_cart();
    	}
    }

    I am trying to do this but with no luck. I don’t exactly have just a cart.php page that I can see. I have a bunch of pages that have the word cart in it but not one specifically just cart. php.

    Any help would be greatly appreciated.

    Works great derekseymour
    Thanks!

    Shnize,
    The cart.php file is under the cart folder, under templates.
    I put it in about line 135.
    Just keep it out of the php stream.

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

    This does beg the question why isn’t there a do_action woocommerce_empty_cart?

    João G

    @joaosvu

    derekseymour, worked like a charm! thanks man.

    Thanks a lot derekseymour!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Add an empty cart button to cart page’ is closed to new replies.