How to Add an Empty Cart Button in WooCommerce
A customer fills a cart while browsing, changes their mind, and wants to start again. In a default WooCommerce store, they have to remove every item one at a time. With a long cart, that is tedious, and some customers give up on the store instead.
In this guide, you will learn why WooCommerce has no empty cart button, how to add one with code, and how to add a safer version with an undo option using a plugin.
Why add an empty cart button?
- Large carts. Customers who add many items, such as trade buyers or shoppers comparing options, need a quick way to start over.
- Testing and comparing. Shoppers often build a cart to check totals or shipping, then want to clear it.
- A cleaner experience. One clear action is easier than many small “remove” clicks.
Does WooCommerce have an empty cart button?
No. WooCommerce only shows a remove link next to each item in the cart. There is no built-in button to clear the whole cart at once.
Method 1: Add an empty cart button with code
If you are comfortable editing code, you can add a basic button with a snippet. Add this to your child theme’s functions.php or a code snippets plugin:
// Show an "Empty cart" button below the cart table.
add_action( 'woocommerce_cart_actions', function () {
$url = wp_nonce_url( add_query_arg( 'empty-cart', '1', wc_get_cart_url() ), 'empty_cart' );
echo '<a class="button" href="' . esc_url( $url ) . '">Empty cart</a>';
} );
// Empty the cart when the button is clicked.
add_action( 'template_redirect', function () {
if ( isset( $_GET['empty-cart'], $_GET['_wpnonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'empty_cart' ) ) {
WC()->cart->empty_cart();
wp_safe_redirect( wc_get_cart_url() );
exit;
}
} );
This works for a simple setup, but it has limits:
- It only works on the classic cart, not the newer WooCommerce block cart.
- It reloads the whole page.
- There is no confirmation and no way to undo a mistaken click.
- Styling and placement need more code.
Method 2: Add an empty cart button with a plugin
Our One Click Empty Cart plugin adds a customisable empty cart button without code. With it, you can:
- Empty the cart via AJAX, with no full page reload.
- Show an Undo message that lets customers restore their items within a time you set, from 2 to 30 seconds.
- Add an optional confirmation dialog before the cart is cleared.
- Choose a button style (outline, solid or text link), colour and label.
- Place the button above the cart table, below it, or next to the coupon field.
- Decide where customers go next: stay on the cart, or go to the shop, the homepage or a custom URL.
- Use it on both the classic cart and the WooCommerce block cart.
Setting it up takes a few steps:
- First, install and activate the plugin.
- Then go to WooCommerce → Settings → Products → Empty Cart Button.
- Next, choose the style, label, colour and position.
- Finally, decide whether to use the confirmation dialog and the undo message, and set where customers go after clearing the cart.
Confirmation or undo: which should you use?
Both prevent accidental clicks, but they feel different to customers:
- A confirmation dialog asks before anything happens. It is safe, but it adds an extra click every time.
- An undo message clears the cart straight away and gives customers a few seconds to change their mind. It feels faster and still protects against mistakes.
For most stores, the undo message alone is enough.
Conclusion
WooCommerce makes customers remove cart items one by one. A WooCommerce empty cart button lets them start over in one click. You can add a basic version with code, or use One Click Empty Cart for an AJAX button with undo, custom styling and block cart support.
Also, if customers build large carts because they need a price first, Cart to Quote and Social Share lets them request a quote straight from the cart. You can explore all our WooCommerce plugins too.
Join the discussion