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
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
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:
Also you can put that Clear Cart button on anywhere in your Prestashop 1.7 website
Leave a reply
You must be logged in to post a comment.
2 Comments
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
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.