在jQuery中update_checkout
触发后,结帐页面会刷新,其中包含付款明细,从而删除了输入的卡明细。
我添加了自定义代码来存储和恢复卡的详细信息,但是我可以看到该代码存在于plugins/woocommerce/assets/js/frontend/checkout.js
中,该代码已经在执行相同的操作,但是似乎无法正常工作。
// 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();
}
}
});
// Fill in the payment details if possible without overwriting data if set.
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 if ( null !== $( this ).val() && 0 === $( this ).val().length ) {
$( this ).val( paymentDetails[ ID ] ).change();
}
}
});
}
输入卡详细信息后,应将其恢复。