Handle login and change events
This commit is contained in:
parent
e5192cfeff
commit
cfe1cb5c16
|
@ -10,7 +10,8 @@ jQuery( function( $ ) {
|
||||||
|
|
||||||
// Params.
|
// Params.
|
||||||
this.params = $.extend( {}, {
|
this.params = $.extend( {}, {
|
||||||
'is_registration_required': false
|
'is_registration_required': false,
|
||||||
|
'is_logged_in' : false,
|
||||||
}, wc_tokenization_form_params );
|
}, wc_tokenization_form_params );
|
||||||
|
|
||||||
// Bind functions to this.
|
// Bind functions to this.
|
||||||
|
@ -21,7 +22,7 @@ jQuery( function( $ ) {
|
||||||
this.hideSaveNewCheckbox = this.hideSaveNewCheckbox.bind( this );
|
this.hideSaveNewCheckbox = this.hideSaveNewCheckbox.bind( this );
|
||||||
|
|
||||||
// When a radio button is changed, make sure to show/hide our new CC info area.
|
// When a radio button is changed, make sure to show/hide our new CC info area.
|
||||||
this.$target.on( 'click', ':input.woocommerce-SavedPaymentMethods-tokenInput', { tokenizationForm: this }, this.onTokenChange );
|
this.$target.on( 'click change', ':input.woocommerce-SavedPaymentMethods-tokenInput', { tokenizationForm: this }, this.onTokenChange );
|
||||||
|
|
||||||
// OR if create account is checked.
|
// OR if create account is checked.
|
||||||
$( 'input#createaccount' ).change( { tokenizationForm: this }, this.onCreateAccountChange );
|
$( 'input#createaccount' ).change( { tokenizationForm: this }, this.onCreateAccountChange );
|
||||||
|
@ -38,21 +39,21 @@ jQuery( function( $ ) {
|
||||||
|
|
||||||
// Don't show the "use new" radio button if we only have one method..
|
// Don't show the "use new" radio button if we only have one method..
|
||||||
if ( 0 === this.$target.data( 'count' ) ) {
|
if ( 0 === this.$target.data( 'count' ) ) {
|
||||||
$( '.woocommerce-SavedPaymentMethods-new', this.$target ).hide();
|
$( '.woocommerce-SavedPaymentMethods-new', this.$target ).remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger change event
|
|
||||||
$( ':input.woocommerce-SavedPaymentMethods-tokenInput:checked', this.$target ).trigger( 'change' );
|
|
||||||
|
|
||||||
// Hide "save card" if "Create Account" is not checked and registration is not forced.
|
// Hide "save card" if "Create Account" is not checked and registration is not forced.
|
||||||
var hasCreateAccountCheckbox = 0 < $( 'input#createaccount' ).length,
|
var hasCreateAccountCheckbox = 0 < $( 'input#createaccount' ).length,
|
||||||
createAccount = hasCreateAccountCheckbox && $('input#createaccount').is( ':checked' );
|
createAccount = hasCreateAccountCheckbox && $( 'input#createaccount' ).is( ':checked' );
|
||||||
|
|
||||||
if ( createAccount || this.params.is_registration_required ) {
|
if ( createAccount || this.params.is_logged_in || this.params.is_registration_required ) {
|
||||||
this.showSaveNewCheckbox();
|
this.showSaveNewCheckbox();
|
||||||
} else {
|
} else {
|
||||||
this.hideSaveNewCheckbox();
|
this.hideSaveNewCheckbox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trigger change event
|
||||||
|
$( ':input.woocommerce-SavedPaymentMethods-tokenInput:checked', this.$target ).trigger( 'change' );
|
||||||
};
|
};
|
||||||
|
|
||||||
TokenizationForm.prototype.onTokenChange = function( event ) {
|
TokenizationForm.prototype.onTokenChange = function( event ) {
|
||||||
|
@ -97,7 +98,7 @@ jQuery( function( $ ) {
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* Initialize.
|
* Initialize.
|
||||||
*/
|
*/
|
||||||
$( document.body ).on( 'updated_checkout wc-credit-card-form-init', function() {
|
$( document.body ).on( 'updated_checkout wc-credit-card-form-init', function() {
|
||||||
|
|
|
@ -445,6 +445,7 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
||||||
wp_localize_script(
|
wp_localize_script(
|
||||||
'woocommerce-tokenization-form', 'wc_tokenization_form_params', array(
|
'woocommerce-tokenization-form', 'wc_tokenization_form_params', array(
|
||||||
'is_registration_required' => WC()->checkout()->is_registration_required(),
|
'is_registration_required' => WC()->checkout()->is_registration_required(),
|
||||||
|
'is_logged_in' => is_user_logged_in(),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue