Skip to content

Magento 2 : How To Show Custom Notice Message Before Payment Step on Checkout

I want to show alert box to customer after I click on “Next” button. if the Cart Subtotal is more than $100
enter image description here

I try to put this function in Magento_Checkout/templates/onepage.phtml but nothing hapenned.

    $(document).on('click', '.button.action.continue.primary', function (event) {`
    
    var orderTotal = parseFloat($('.totals.sub.price').text().replace('$', ''));

    if (orderTotal > 100) {
        alert({
            title: $.mage.__('Order Total Alert'),
            content: $.mage.__('Your Order Total exceeds $100.'),
            actions: {
                always: function () {
                }
            }
        });
    } else {default action
        $(this).off('click').trigger('click');
    }
});

did I do something wrong?