Change the submit payment button based on the payment in magento2

We don’t have any default method to change the payment button name based on the payment method. So we need to use a custom method for the same.
For that, we could use the JS function to change the payment method name based on the payment method name selection.
Magento_Checkout/web/js/view/payment/default.js

selectPaymentMethod: function () {
            if (this.item.method == 'stripe_payments') {
                $('.actions-toolbar button').text($.mage.__('Confirm & Pay'));
            } else {
                $('.actions-toolbar button').text($.mage.__('Confirm'));
            }
            selectPaymentMethodAction(this.getData());
            checkoutData.setSelectedPaymentMethod(this.item.method);

            return true;
        },

On the selectPaymentMethod default function we have added a condition to show the button name based on the payment method.

And use getTitle method to use condition to set payment button title on page refresh.

Thank you.

Leave a comment

Your email address will not be published. Required fields are marked *