Remove the need for token script when logged out
This commit is contained in:
parent
1d37b9f4e7
commit
6fe37fff33
|
@ -1,4 +1,3 @@
|
||||||
/* global woocommerceTokenizationParams */
|
|
||||||
( function( $, data ) {
|
( function( $, data ) {
|
||||||
$( function() {
|
$( function() {
|
||||||
var wcTokenizationForm = (function() {
|
var wcTokenizationForm = (function() {
|
||||||
|
@ -10,7 +9,7 @@
|
||||||
this.onTokenChange = function() {
|
this.onTokenChange = function() {
|
||||||
if ( 'new' === $( this ).val() ) {
|
if ( 'new' === $( this ).val() ) {
|
||||||
$wcTokenizationForm.showForm();
|
$wcTokenizationForm.showForm();
|
||||||
$wcTokenizationForm.showSaveNewCheckboxForLoggedInOnly();
|
$wcTokenizationForm.showSaveNewCheckbox();
|
||||||
} else {
|
} else {
|
||||||
$wcTokenizationForm.hideForm();
|
$wcTokenizationForm.hideForm();
|
||||||
$wcTokenizationForm.hideSaveNewCheckbox();
|
$wcTokenizationForm.hideSaveNewCheckbox();
|
||||||
|
@ -31,8 +30,8 @@
|
||||||
$( ':input.wc-gateway-payment-token:last', $target ).prop( 'checked', true );
|
$( ':input.wc-gateway-payment-token:last', $target ).prop( 'checked', true );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Don't show the "use new" radio button if we are a guest or only have one method..
|
// Don't show the "use new" radio button if we only have one method..
|
||||||
if ( 0 === $target.data( 'count' ) || ! data.userLoggedIn ) {
|
if ( 0 === $target.data( 'count' ) ) {
|
||||||
$( '.wc-payment-form-new-checkbox-wrap', $target ).hide();
|
$( '.wc-payment-form-new-checkbox-wrap', $target ).hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,14 +55,6 @@
|
||||||
$( '.wc-new-payment-method-wrap', $formWrap ).hide();
|
$( '.wc-new-payment-method-wrap', $formWrap ).hide();
|
||||||
};
|
};
|
||||||
|
|
||||||
this.showSaveNewCheckboxForLoggedInOnly = function() {
|
|
||||||
if ( data.userLoggedIn ) {
|
|
||||||
$wcTokenizationForm.showSaveNewCheckbox();
|
|
||||||
} else {
|
|
||||||
$wcTokenizationForm.hideSaveNewCheckbox();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// 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
|
||||||
$( ':input.wc-gateway-payment-token', $target ).change( this.onTokenChange );
|
$( ':input.wc-gateway-payment-token', $target ).change( this.onTokenChange );
|
||||||
|
|
||||||
|
@ -85,4 +76,4 @@
|
||||||
} );
|
} );
|
||||||
} );
|
} );
|
||||||
});
|
});
|
||||||
})( jQuery, woocommerceTokenizationParams );
|
})( jQuery );
|
||||||
|
|
|
@ -359,21 +359,30 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
||||||
return apply_filters( 'woocommerce_payment_gateway_supports', in_array( $feature, $this->supports ) ? true : false, $feature, $this );
|
return apply_filters( 'woocommerce_payment_gateway_supports', in_array( $feature, $this->supports ) ? true : false, $feature, $this );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Core credit card form which gateways can used if needed. Deprecated - inheirt WC_Payment_Gateway_CC instead.
|
||||||
|
* @param array $args
|
||||||
|
* @param array $fields
|
||||||
|
*/
|
||||||
|
public function credit_card_form( $args = array(), $fields = array() ) {
|
||||||
|
_deprecated_function( 'credit_card_form', '2.6', 'WC_Payment_Gateway_CC->form' );
|
||||||
|
$cc_form = new WC_Payment_Gateway_CC;
|
||||||
|
$cc_form->id = $this->id;
|
||||||
|
$cc_form->supports = $this->supports;
|
||||||
|
$cc_form->form();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enqueues our tokenization script to handle some of the new form options.
|
* Enqueues our tokenization script to handle some of the new form options.
|
||||||
* @since 2.6.0
|
* @since 2.6.0
|
||||||
*/
|
*/
|
||||||
public function tokenization_script() {
|
public function tokenization_script() {
|
||||||
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
|
|
||||||
wp_enqueue_script(
|
wp_enqueue_script(
|
||||||
'woocommerce-tokenization-form',
|
'woocommerce-tokenization-form',
|
||||||
plugins_url( '/assets/js/frontend/tokenization-form' . $suffix . '.js', WC_PLUGIN_FILE ),
|
plugins_url( '/assets/js/frontend/tokenization-form' . ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min' ) . '.js', WC_PLUGIN_FILE ),
|
||||||
array( 'jquery' ),
|
array( 'jquery' ),
|
||||||
WC()->version
|
WC()->version
|
||||||
);
|
);
|
||||||
wp_localize_script( 'woocommerce-tokenization-form', 'woocommerceTokenizationParams', array(
|
|
||||||
'userLoggedIn' => (bool) is_user_logged_in(),
|
|
||||||
) );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -477,17 +486,4 @@ abstract class WC_Payment_Gateway extends WC_Settings_API {
|
||||||
$html .= '</label>';
|
$html .= '</label>';
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Core credit card form which gateways can used if needed. Deprecated - inheirt WC_Payment_Gateway_CC instead.
|
|
||||||
* @param array $args
|
|
||||||
* @param array $fields
|
|
||||||
*/
|
|
||||||
public function credit_card_form( $args = array(), $fields = array() ) {
|
|
||||||
_deprecated_function( 'credit_card_form', '2.6', 'WC_Payment_Gateway_CC->form' );
|
|
||||||
$cc_form = new WC_Payment_Gateway_CC;
|
|
||||||
$cc_form->id = $this->id;
|
|
||||||
$cc_form->supports = $this->supports;
|
|
||||||
$cc_form->form();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue