How to creating a “Clear cart” button for clear all products from a Cart in PrestaShop 1.7?

If you want display a Clear Cart button in Mini Cart or in Cart page of Prestashop 1.7. When click this button, it will clear all products from a Cart in PrestaShop 1.7 like this image

clear-cart-button-1

You can follow steps

Step 1: Open file

PRESTASHOP_ROOT\themes\YOURTHEME\templates\checkout\cart.tpl

Example:

PRESTASHOP_ROOT\themes\classic\templates\checkout\cart.tpl

Add this source code below: <div class=”cart-grid-body col-xs-12 col-lg-8″>  or any placements which you want display “Clear Cart” button

<!– add Clear Cart button –>
<a href=”{url entity=’cart’ params=[‘clearcart’ => ‘1’]}” class=”btn btn-primary” style=”margin: 10px 0;”>
{l s=’Clear Cart’ d=’Shop.Theme.Checkout’}
</a>
<!– end Clear Cart –>

See my picture

clear-cart-button-2

Step 2: Edit CartController.php

Open the file: PRESTASHOP_ROOT\controllers\front\CartController.php

find a function: initContent()

Add this source code

if (Tools::getIsset(‘clearcart’)) {
$this->context->cart->delete();
$this->context->cookie->id_cart = 0;
Tools::redirect(‘index.php’);
}

After line

if (Configuration::isCatalogMode() && Tools::getValue(‘action’) === ‘show’) {
Tools::redirect(‘index.php’);
}

See my picture:

clear-cart-button-3

Also you can put that Clear Cart button on anywhere in your Prestashop 1.7 website

Related Articles

2 Comments

  1. eumedia September 23, 2019 at 2:59 pm

    Nice day,
    This does not work with PS 1.7.5.2.
    It only works if I add the product and delete it immediately.
    If I continue to checkout and go back, the delete cart button does not work.
    Please help, thank you
    Roman

    • Tony January 11, 2020 at 12:22 pm

      for your issue:
      Please open a ticket https://taydoapp.com/helpdesk
      we can check this issue for help you.
      If you need any our support. We are always ready to work.
      Thanks.

Leave a reply

You must be logged in to post a comment.