<script type="text/javascript">
jQuery(function($) {
jQuery( function( $ ) {
var ppec_mark_fields = '#woocommerce_ppec_paypal_title, #woocommerce_ppec_paypal_description';
var ppec_live_fields = '#woocommerce_ppec_paypal_api_username, #woocommerce_ppec_paypal_api_password, #woocommerce_ppec_paypal_api_signature, #woocommerce_ppec_paypal_api_certificate, #woocommerce_ppec_paypal_api_subject';
var ppec_sandbox_fields = '#woocommerce_ppec_paypal_sandbox_api_username, #woocommerce_ppec_paypal_sandbox_api_password, #woocommerce_ppec_paypal_sandbox_api_signature, #woocommerce_ppec_paypal_sandbox_api_certificate, #woocommerce_ppec_paypal_sandbox_api_subject';
var enable_toggle = $( 'a.ppec-toggle-settings' ).length > 0;
var enable_sandbox_toggle = $( 'a.ppec-toggle-sandbox-settings' ).length > 0;
$( '#woocommerce_ppec_paypal_environment' ).change(function(){
$( ppec_sandbox_fields + ',' + ppec_live_fields ).closest( 'tr' ).hide();
if ( 'live' === $( this ).val() ) {
$( '#woocommerce_ppec_paypal_api_credentials, #woocommerce_ppec_paypal_api_credentials + p' ).show();
$( '#woocommerce_ppec_paypal_sandbox_api_credentials, #woocommerce_ppec_paypal_sandbox_api_credentials + p' ).hide();
if ( ! enable_toggle ) {
$( ppec_live_fields ).closest( 'tr' ).show();
}
} else {
$( '#woocommerce_ppec_paypal_api_credentials, #woocommerce_ppec_paypal_api_credentials + p' ).hide();
$( '#woocommerce_ppec_paypal_sandbox_api_credentials, #woocommerce_ppec_paypal_sandbox_api_credentials + p' ).show();
if ( ! enable_sandbox_toggle ) {
$( ppec_sandbox_fields ).closest( 'tr' ).show();
}
}
}).change();
$( '#woocommerce_ppec_paypal_enabled' ).change(function(){
if ( $( this ).is( ':checked' ) ) {
$( ppec_mark_fields ).closest( 'tr' ).show();
} else {
$( ppec_mark_fields ).closest( 'tr' ).hide();
}
}).change();
$( '#woocommerce_ppec_paypal_paymentaction' ).change(function(){
if ( 'sale' === $( this ).val() ) {
$( '#woocommerce_ppec_paypal_instant_payments' ).closest( 'tr' ).show();
} else {
$( '#woocommerce_ppec_paypal_instant_payments' ).closest( 'tr' ).hide();
}
}).change();
if ( enable_toggle ) {
$( document ).on( 'click', '.ppec-toggle-settings', function( e ) {
$( ppec_live_fields ).closest( 'tr' ).toggle( 'fast' );
e.preventDefault();
} );
}
if ( enable_sandbox_toggle ) {
$( document ).on( 'click', '.ppec-toggle-sandbox-settings', function( e ) {
$( ppec_sandbox_fields ).closest( 'tr' ).toggle( 'fast' );
e.preventDefault();
} );
}
});
});
</script>