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,17 +55,21 @@ jQuery( function( $ ) {
|
|||
$( '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"]' );
|
||||
|
||||
// If there is one method, we can hide the radio input
|
||||
if ( 1 === $payment_methods.length ) {
|
||||
$payment_methods.eq(0).hide();
|
||||
}
|
||||
if ( selectedPaymentMethod ) {
|
||||
$( '#' + selectedPaymentMethod ).prop( 'checked', true );
|
||||
} else {
|
||||
// If there is one method, we can hide the radio input
|
||||
if ( 1 === $payment_methods.length ) {
|
||||
$payment_methods.eq(0).hide();
|
||||
}
|
||||
|
||||
// If there are none selected, select the first.
|
||||
if ( 0 === $payment_methods.filter( ':checked' ).length ) {
|
||||
$payment_methods.eq(0).prop( 'checked', true );
|
||||
// If there are none selected, select the first.
|
||||
if ( 0 === $payment_methods.filter( ':checked' ).length ) {
|
||||
$payment_methods.eq(0).prop( 'checked', true );
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger click event for selected method
|
||||
|
@ -271,6 +275,9 @@ jQuery( function( $ ) {
|
|||
url: wc_checkout_params.wc_ajax_url.toString().replace( '%%endpoint%%', 'update_order_review' ),
|
||||
data: data,
|
||||
success: function( data ) {
|
||||
|
||||
var selectedPaymentMethod = $( '.woocommerce-checkout' ).find( 'input[name="payment_method"]' ).filter( ':checked' ).attr( 'id' );
|
||||
|
||||
// Reload the page if requested
|
||||
if ( 'true' === data.reload ) {
|
||||
window.location.reload();
|
||||
|
@ -321,7 +328,7 @@ jQuery( function( $ ) {
|
|||
}
|
||||
|
||||
// Re-init methods
|
||||
wc_checkout_form.init_payment_methods();
|
||||
wc_checkout_form.init_payment_methods( selectedPaymentMethod );
|
||||
|
||||
// Fire updated_checkout e
|
||||
$( document.body ).trigger( 'updated_checkout' );
|
||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue