Adding an Empty Cart button to your store might look like a bad idea. Why would you want to make easier for your customers to empty the cart with one click? You don’t want them to leave without buying!

Do you know what is even worse than that? Having a grumpy customer. If the customer doesn’t want to buy it’s not a missing Empty Cart button that will make the difference.

So make their life easier and add it.

Open your functions.php file in wp-content/themes/your-child-theme-name/ and add this code at the end of the file:

This code adds the button right after the Apply Coupon button on the Cart page.

An image of the Empty Cart button in the Cart page

Of course, just the button alone is not enough. You need to add some more code right after the previous one:

This is the logic that handles the Empty Cart button, and removes all the products at once, redirecting to the cart page again.

Creating a custom Empty Cart button

With this code in place, you can also create a custom button or a simple link to empty the cart. Just get any link in your site and add the parameter ?empty_cart=yes to it.

Here are two different examples:

  • https://domain.com/product/awesome-product/?empty_cart=yes
  • https://domain.com/?utm=something&empty_cart=yes
0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

You have to agree to the comment policy.

This site uses Akismet to reduce spam. Learn how your comment data is processed.