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) {
        getId = $(this).attr('data-order');
            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;

1 Answer 1


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

<button type="submit"
        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{
    <span><?php /* @escapeNotVerified */ echo __('Clear Shopping Cart'); ?></span>

Your Answer

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

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