Magento – How to add confirm modal popup on clear shopping cart magento2

magento2requirejsshopping-cart

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>

Best Answer

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>