Merge pull request #12821 from woocommerce/fix-12713

Don’t erase payment details w/ ‘update_checkout’
This commit is contained in:
Mike Jolley 2017-01-26 14:07:31 +00:00 committed by GitHub
commit 173543ba82
1 changed files with 29 additions and 0 deletions

View File

@ -290,6 +290,20 @@ jQuery( function( $ ) {
var termsCheckBoxChecked = $( '#terms' ).prop( 'checked' );
// Save payment details to a temporary object
var paymentDetails = {};
$( '.payment_box input' ).each( function() {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
paymentDetails[ ID ] = $( this ).prop( 'checked' );
} else {
paymentDetails[ ID ] = $( this ).val();
}
}
});
// Always update the fragments
if ( data && data.fragments ) {
$.each( data.fragments, function ( key, value ) {
@ -303,6 +317,21 @@ jQuery( function( $ ) {
$( '#terms' ).prop( 'checked', true );
}
// Fill in the payment details if possible
if ( ! $.isEmptyObject( paymentDetails ) ) {
$( '.payment_box input' ).each( function() {
var ID = $( this ).attr( 'id' );
if ( ID ) {
if ( $.inArray( $( this ).attr( 'type' ), [ 'checkbox', 'radio' ] ) !== -1 ) {
$( this ).prop( 'checked', paymentDetails[ ID ] ).change();
} else {
$( this ).val( paymentDetails[ ID ] ).change();
}
}
});
}
// Check for error
if ( 'failure' === data.result ) {