Removed extra check if the code is executed within admin.

This commit is contained in:
Peter Fabian 2019-06-20 14:07:52 +02:00
parent 91839ce078
commit a6a26633a4
1 changed files with 22 additions and 24 deletions

View File

@ -198,32 +198,30 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
* Static so that's enqueued only once. * Static so that's enqueued only once.
*/ */
public static function enqueue_admin_js() { public static function enqueue_admin_js() {
if ( is_admin() ) { wc_enqueue_js(
wc_enqueue_js( "jQuery( function( $ ) {
"jQuery( function( $ ) { function wcFreeShippingShowHideMinAmountField( el ) {
function wcFreeShippingShowHideMinAmountField( el ) { var form = $( el ).closest( 'form' );
var form = $( el ).closest( 'form' ); var minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' );
var minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' ); if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) {
if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) { minAmountField.hide();
minAmountField.hide(); } else {
} else { minAmountField.show();
minAmountField.show();
}
} }
}
$( document.body ).on( 'change', '#woocommerce_free_shipping_requires', function() { $( document.body ).on( 'change', '#woocommerce_free_shipping_requires', function() {
wcFreeShippingShowHideMinAmountField( this ); wcFreeShippingShowHideMinAmountField( this );
}); });
// Change while load. // Change while load.
$( '#woocommerce_free_shipping_requires' ).change(); $( '#woocommerce_free_shipping_requires' ).change();
$( document.body ).on( 'wc_backbone_modal_loaded', function( evt, target ) { $( document.body ).on( 'wc_backbone_modal_loaded', function( evt, target ) {
if ( 'wc-modal-shipping-method-settings' === target ) { if ( 'wc-modal-shipping-method-settings' === target ) {
wcFreeShippingShowHideMinAmountField( $( '#wc-backbone-modal-dialog #woocommerce_free_shipping_requires', evt.currentTarget ) ); wcFreeShippingShowHideMinAmountField( $( '#wc-backbone-modal-dialog #woocommerce_free_shipping_requires', evt.currentTarget ) );
} }
} ); } );
});" });"
); );
}
} }
} }