Create a “Empty Cart” button for WooCommerce

Remi | August 5, 2013 | in Tutorials

Here is quick tutorial to show you how to add a “Empty Cart” button on the WooCommerce cart page. Here is the result:


To do so, there are two steps. The first one is to add this little snippet in your functions.php file (this file is located in your theme folder):

And the second step is to create a custom template for the cart. Basically a custom template allow you to override WooCommerce default files and use your own custom files instead. Here is a quick tutorial that will explain you how to create your custom templates:

Finally, in “templates/cart/cart.php”, add at line 134 the HTML code to output the button:

And that’s it! ;-)


The author

About the author Remi: Hey! My name is Rémi Corson, i'm a WordPress Expert Developer, i create high level themes and plugins, and i provide free stuff every week on this website!


    1. Seth Neal

      Michael, did you ever find out a way to have the cart clear after a set period of time? I have a one product site that skips the cart–which is great–except if people have abandoned checkout previously and then go to buy the product again they have multiple items at check out.

      1. Jeff

        Like so?

        // check for empty-cart get param to clear the cart
        add_action( ‘init’, ‘woocommerce_clear_cart_url’ );
        function woocommerce_clear_cart_url() {
        global $woocommerce;

        if ( isset( $_GET[’empty-cart’] ) ) {

          1. Jeff

            Sorry to keep bugging you but just trying to get this to work.

            I’m actually trying to add this to the checkout page. Is there something in the function that needs to be modified for the link to work on the checkout page?

            Based on the php code that existed before, I rewrote the link like this:

            cart->get_cart_url() . ‘?empty-cart”> Empty Cart

            Unfortunately, that is linking to ‘’.

            Thanks again for your help.

          2. Jeff

            I take all that back. Everything works so thank you so much!

            Just so you know, this button was the key for me to get rid of the cart page entirely.

            In the settings, I change the cart page from “Cart” to “Checkout”.

            Then I added remove links for each item in the order review table on the checkout page so that you can still edit the “cart.”

            I used your “empty cart” button instead of an ordinary “remove from cart” link only if there is only one item left in the cart. Then by adding the redirect, the checkout page doesn’t fail due to an empty cart.

      2. madzzoni

        Hello Remi, I’ve tried this redirect snippet in my theme functions.php, because the Checkout-page makes to many redirect Loop when empty the Cart:

        add_action( ‘init’, ‘woocommerce_clear_cart_url’ );
        function woocommerce_clear_cart_url() {
        global $woocommerce;

        if ( isset( $_GET['empty-cart'] ) ) {
        wp_redirect(''); exit;

        But when i try to empty the Cart on my Checkout-page ( the page still makes to many redirect Loops instead of redirect.

        Can you help med here??


      1. darrentucs

        Hi Remi,

        Ok Ive done that, but everytime I click the empty cart button, I just get redirected to the cart page.

        Ive cleared the cache, killed all cookies and sessions and same thing.

        Is there something im doing wrong?

          1. darrentucs

            That’s correct. I just get redirected back to the cart page and the cart doesn’t empty.

            I’d like to redirect it back to a specific page, but I need the cart to empty first.

  1. Pippa

    Dear Remi,

    thank you so much for this nice tut!

    Unfortunately, I can’t get the button to work in my checkout page, it breaks the site.

    I would appreciate if you have an instruction for dummies.

    Kind regards!

  2. pcooper114

    Hey Remi,

    I’m working on a site that bypasses the cart page altogether. The client wants them to be able to click buy and go directly to checkout…. However, they are now realizing that doing that means they can’t empty what is already in the cart. Anyway you can make this work for the Checkout page?


  3. sanjays442

    hey remi im facing a problem in quick checkout in woocommerce
    when i add item using quick checkout the item is loaded in cart but when add next item previous item is showing in cart

Leave a reply