Fixed show/hide free amount in modals

This commit is contained in:
Claudio Sanches 2016-07-19 09:33:56 -03:00
parent 19713f8bc7
commit 70bf9bfcd6
1 changed files with 17 additions and 4 deletions

View File

@ -109,14 +109,27 @@ class WC_Shipping_Free_Shipping extends WC_Shipping_Method {
public function get_instance_form_fields() {
wc_enqueue_js( "
jQuery( function( $ ) {
$( '#woocommerce_free_shipping_requires' ).change( function() {
var minAmountField = $( '#woocommerce_free_shipping_min_amount' ).closest( 'tr' );
if ( $(this).val() === 'coupon' || $(this).val() === '' ) {
function wcFreeShippingShowHideminAmountField( el ) {
var form = $( el ).closest( 'form' );
var minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' );
if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) {
minAmountField.hide();
} else {
minAmountField.show();
}
}).change();
}
$( document.body ).on( 'change', '#woocommerce_free_shipping_requires', function() {
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 ) );
}
} );
});
" );