1

How to add pop up modal confirm on click of clear shopping cart in cart page.

I tried with below code but its showing confirm pop up but its clear cart if I confirm or not.

    <script type="text/javascript">
    require(['jquery','Magento_Ui/js/modal/confirm'], function ($, confirm) {
    $('.update').on("click",function(event){
        event.stopPropagation();
        getId = $(this).attr('data-order');
        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;
                }
            }
        });
    });
 function _removeItem(orderId){
           return false;
    },
 });
</script>

1 Answer 1

-1

You could add it to the button directly, like this:

<button type="submit"
        name="update_cart_action"
        data-cart-empty=""
        value="empty_cart"
        title="<?php echo $block->escapeHtml(__('Clear Shopping Cart')); ?>"
        class="action clear" id="empty_cart_button"
        onclick="if(confirm("Are you sure want to clear cart?")){}else{
event.preventDefault()};"
        >
    <span><?php /* @escapeNotVerified */ echo __('Clear Shopping Cart'); ?></span>
</button>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.