Only print js for free shipping fields in admin
Since WC_Shipping_Method->get_option() runs $this->get_instance_form_fields it prints out the JS even when getting the option outsite admin.
This commit is contained in:
parent
500c68d729
commit
58eaa70424
|
@ -107,31 +107,33 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function get_instance_form_fields() {
|
public function get_instance_form_fields() {
|
||||||
wc_enqueue_js( "
|
if ( is_admin() ) {
|
||||||
jQuery( function( $ ) {
|
wc_enqueue_js( "
|
||||||
function wcFreeShippingShowHideMinAmountField( el ) {
|
jQuery( function( $ ) {
|
||||||
var form = $( el ).closest( 'form' );
|
function wcFreeShippingShowHideMinAmountField( el ) {
|
||||||
var minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' );
|
var form = $( el ).closest( 'form' );
|
||||||
if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) {
|
var minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' );
|
||||||
minAmountField.hide();
|
if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) {
|
||||||
} else {
|
minAmountField.hide();
|
||||||
minAmountField.show();
|
} else {
|
||||||
|
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.
|
||||||
|
$( '#woocommerce_free_shipping_requires' ).change();
|
||||||
|
$( document.body ).on( 'wc_backbone_modal_loaded', function( evt, target ) {
|
||||||
|
if ( 'wc-modal-shipping-method-settings' === target ) {
|
||||||
|
wcFreeShippingShowHideMinAmountField( $( '#wc-backbone-modal-dialog #woocommerce_free_shipping_requires', evt.currentTarget ) );
|
||||||
|
}
|
||||||
|
} );
|
||||||
});
|
});
|
||||||
|
" );
|
||||||
// Change while load.
|
}
|
||||||
$( '#woocommerce_free_shipping_requires' ).change();
|
|
||||||
$( document.body ).on( 'wc_backbone_modal_loaded', function( evt, target ) {
|
|
||||||
if ( 'wc-modal-shipping-method-settings' === target ) {
|
|
||||||
wcFreeShippingShowHideMinAmountField( $( '#wc-backbone-modal-dialog #woocommerce_free_shipping_requires', evt.currentTarget ) );
|
|
||||||
}
|
|
||||||
} );
|
|
||||||
});
|
|
||||||
" );
|
|
||||||
|
|
||||||
return parent::get_instance_form_fields();
|
return parent::get_instance_form_fields();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue