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.

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

<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) —

170 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? (AMP Version)

Leave a Reply