WooCommerce Empty Cart Button

WooCommere empty the whole cart with one button click


There are no pre-requisites in order for you to be able to implement this solution.

How To Implement This Solution?

Simply copy the pre-coded solution to your active theme’s functions.php or preferably the Code Snippets Plugin.

About this Solution

By default, WooCommerce only lets users clear items from their cart one by one. This guide shows you how to create one button shown on the cart page which will empty the entire cart in one click. A lot of guides on this topic are using a hook which displays the button next to the coupon field but many store owners don’t have coupons enabled meaning the button does not display. This guide uses the woocommerce_cart_actions hook to display the Empty Cart button next to the Update Cart button.

 * Snippet Name:	WooCommerce Empty Cart Button
 * Snippet Author:	ecommercehints.com	

add_action( 'woocommerce_cart_actions', 'ecommercehints_empty_cart_button' ); // Create the button
function ecommercehints_empty_cart_button() {
	echo '<a href="' . esc_url( add_query_arg( 'empty_cart', 'true' ) ) . '" class="button" title="' . esc_attr( 'Empty Cart', 'woocommerce' ) . '">' . esc_html( 'Empty Cart', 'woocommerce' ) . '</a>';

add_action( 'wp_loaded', 'ecommercehints_empty_cart_button_empty_cart_action', 20 ); // EMpty the cart if empty button is clicked
function ecommercehints_empty_cart_button_empty_cart_action() {
	if ( isset( $_GET['empty_cart'] ) && 'true' === esc_html( $_GET['empty_cart'] ) ) {
		$referer  = wp_get_referer() ? esc_url( remove_query_arg( 'empty_cart' ) ) : wc_get_cart_url();

Snippet Benefits

  • Reduce the number of actions the user has to take to empty their cart, improving the user experience
WooCommerce Conversion Rate Optimisation (CRO) eBook
100 WooCommerce Conversion Rate Optimisation Tips

Leave a Reply

If you are going to write code in the comments, please wrap it between code tags.

Your email address will not be published. Required fields are marked *

Other Recent Guides

Subscribe To Emails

Get exclusive WooCommerce tips that I only share with email subscribers

Join hundreds of other subscribers