Unselect saved card only on page load

If we do it on every form update/method switch, 
then e.g. if the user first selected a card, 
but then entered/edited the address, 
they may lose the selection 
(and maybe it could cause issues in other cases,
if something else triggers update_checkout)
This commit is contained in:
Alex P 2021-11-11 10:57:17 +02:00
parent 2e59248bf9
commit c2b77b3cff

View file

@ -12,9 +12,14 @@ class CheckoutBootstap {
}
init() {
this.render();
// Unselect saved card.
// WC saves form values, so with our current UI it would be a bit weird
// if the user paid with saved, then after some time tries to pay again,
// but wants to enter a new card, and to do that they have to choose “Select payment” in the list.
jQuery('#saved-credit-card').val(jQuery('#saved-credit-card option:first').val());
jQuery(document.body).on('updated_checkout', () => {
this.render()
});
@ -65,8 +70,6 @@ class CheckoutBootstap {
}
switchBetweenPayPalandOrderButton() {
jQuery('#saved-credit-card').val(jQuery('#saved-credit-card option:first').val());
const currentPaymentMethod = this.currentPaymentMethod();
if (currentPaymentMethod !== 'ppcp-gateway' && currentPaymentMethod !== 'ppcp-credit-card-gateway') {