How to Add a Clear-Cart Button in Woocommerce?


The Woocommerce does not provide a clear-all button in the Shopping Cart page. But it is very easy to add one.

Step 1 – Adding Clear-Cart Action

You should add the following PHP code in your child-theme’s functions template to define the clear-cart action.

1
2
3
4
5
6
7
add_action('init', 'woocommerce_clear_cart_url');
function woocommerce_clear_cart_url() {
    global $woocommerce;
    if( isset($_REQUEST['clear-cart']) ) {
        $woocommerce->cart->empty_cart();
    }
}
add_action('init', 'woocommerce_clear_cart_url');
function woocommerce_clear_cart_url() {
	global $woocommerce;
	if( isset($_REQUEST['clear-cart']) ) {
		$woocommerce->cart->empty_cart();
	}
}

Step 2 – Add the HTML Clear-cart button

This normally goes to the cart.php under your child theme’s woocommerce folder e.g. child-theme/woocommerce/cart/cart.php

1
<input type="submit" onclick='javascript:if(!confirm("Clear All Items?")) {return false;}' class="button" name="clear-cart" value="<?php _e('Clear Cart', 'woocommerce'); ?>" />
<input type="submit" onclick='javascript:if(!confirm("Clear All Items?")) {return false;}' class="button" name="clear-cart" value="<?php _e('Clear Cart', 'woocommerce'); ?>" />

–EOF (The Ultimate Computing & Technology Blog) —

GD Star Rating
loading...
187 words
Last Post: How to Show Default Regular Price for Woocommerce/Wordpress based on Sale Price?
Next Post: How to Return a Default Weight for Products in Woocommerce shop?

The Permanent URL is: How to Add a Clear-Cart Button in Woocommerce?

Leave a Reply