After payment form fragments are updated, make sure to set the previously selected payment method back as the selected/default payment method.
This commit is contained in:
parent
6e1a640b1c
commit
1f25dc001b
|
@ -55,9 +55,12 @@ jQuery( function( $ ) {
|
||||||
$( 'input#createaccount' ).change( this.toggle_create_account ).change();
|
$( 'input#createaccount' ).change( this.toggle_create_account ).change();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
init_payment_methods: function() {
|
init_payment_methods: function( selectedPaymentMethod ) {
|
||||||
var $payment_methods = $( '.woocommerce-checkout' ).find( 'input[name="payment_method"]' );
|
var $payment_methods = $( '.woocommerce-checkout' ).find( 'input[name="payment_method"]' );
|
||||||
|
|
||||||
|
if ( selectedPaymentMethod ) {
|
||||||
|
$( '#' + selectedPaymentMethod ).prop( 'checked', true );
|
||||||
|
} else {
|
||||||
// If there is one method, we can hide the radio input
|
// If there is one method, we can hide the radio input
|
||||||
if ( 1 === $payment_methods.length ) {
|
if ( 1 === $payment_methods.length ) {
|
||||||
$payment_methods.eq(0).hide();
|
$payment_methods.eq(0).hide();
|
||||||
|
@ -67,6 +70,7 @@ jQuery( function( $ ) {
|
||||||
if ( 0 === $payment_methods.filter( ':checked' ).length ) {
|
if ( 0 === $payment_methods.filter( ':checked' ).length ) {
|
||||||
$payment_methods.eq(0).prop( 'checked', true );
|
$payment_methods.eq(0).prop( 'checked', true );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Trigger click event for selected method
|
// Trigger click event for selected method
|
||||||
$payment_methods.filter( ':checked' ).eq(0).trigger( 'click' );
|
$payment_methods.filter( ':checked' ).eq(0).trigger( 'click' );
|
||||||
|
@ -271,6 +275,9 @@ jQuery( function( $ ) {
|
||||||
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'update_order_review' ),
|
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'update_order_review' ),
|
||||||
data: data,
|
data: data,
|
||||||
success: function( data ) {
|
success: function( data ) {
|
||||||
|
|
||||||
|
var selectedPaymentMethod = $( '.woocommerce-checkout' ).find( 'input[name="payment_method"]' ).filter( ':checked' ).attr( 'id' );
|
||||||
|
|
||||||
// Reload the page if requested
|
// Reload the page if requested
|
||||||
if ( 'true' === data.reload ) {
|
if ( 'true' === data.reload ) {
|
||||||
window.location.reload();
|
window.location.reload();
|
||||||
|
@ -321,7 +328,7 @@ jQuery( function( $ ) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Re-init methods
|
// Re-init methods
|
||||||
wc_checkout_form.init_payment_methods();
|
wc_checkout_form.init_payment_methods( selectedPaymentMethod );
|
||||||
|
|
||||||
// Fire updated_checkout e
|
// Fire updated_checkout e
|
||||||
$( document.body ).trigger( 'updated_checkout' );
|
$( document.body ).trigger( 'updated_checkout' );
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue