cancel
Showing results for 
Search instead for 
Did you mean: 

Clear Shopping cart Alert

Clear Shopping cart Alert

Dear team,

 

I want Magento UI with an alert message before clearing the item in the shopping cart. I have used below code in

\vendor\magento\module-checkout\view\frontend\templates\cart\form.phtml

 

Without clicking Ok or Cancel button its automatically clear the data and redirected. Can anyone help me

 

Browser alert will be working good. but I need an alert message with Magento UI. 

 

My Code is below:

 

<button type="submit"
name="update_cart_action"
data-cart-empty=""
value="empty_cart"
title="<?= $block->escapeHtml(__('Clear Shopping Cart')) ?>"
class="action clear" id="empty_cart_button">
<span><?= /* @escapeNotVerified */ __('Clear Shopping Cart') ?></span>
</button>

 

 

<script type="text/javascript">
require(['jquery','Magento_Ui/js/modal/confirm'], function ($, confirm) {

$('.clear').on("click",function(event){
event.stopPropagation();
//event.preventDefault()
confirm({
content: 'Are you sure you would like to remove these item from the shopping cart?',
actions: {
confirm: function () {
return true;
},
cancel: function (event) {
return false;
}
}
});
});
});
</script> 

 

 

1 REPLY 1

Re: Clear Shopping cart Alert

Try this,

 

You have to override form.phtml file

app/design/frontend/vendorname/themename/Magento_Checkout/templates/cart/form.phtml

add the code atlast,

<script>require(['jquery', 'jquery/ui'], function($){ 
        jQuery('.action-delete').click(function(e)
    {
        if(confirm('Do you want to remove this product?'))
        {
            return true;
        }
        else
        {
            return false; 
        }

    });
 });
</script>