WC_Shipping_Free_Shipping::enqueue_admin_jspublic staticWC 1.0

Enqueue JS to handle free shipping options.

Static so that's enqueued only once.

Method of the class: WC_Shipping_Free_Shipping{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = WC_Shipping_Free_Shipping::enqueue_admin_js();

WC_Shipping_Free_Shipping::enqueue_admin_js() code WC 10.8.1

public static function enqueue_admin_js() {
	$handle = 'wc-admin-shipping-free-shipping';
	wp_register_script( $handle, '', array( 'jquery' ), WC_VERSION, array( 'in_footer' => true ) );
	wp_enqueue_script( $handle );
	wp_add_inline_script(
		$handle,
		"jQuery( function( $ ) {
			function wcFreeShippingShowHideMinAmountField( el ) {
				const form = $( el ).closest( 'form' );
				const minAmountField = $( '#woocommerce_free_shipping_min_amount', form ).closest( 'tr' );
				const ignoreDiscountField = $( '#woocommerce_free_shipping_ignore_discounts', form ).closest( 'tr' );
				if ( 'coupon' === $( el ).val() || '' === $( el ).val() ) {
					minAmountField.hide();
					ignoreDiscountField.hide();
				} else {
					minAmountField.show();
					ignoreDiscountField.show();
				}
			}

			$( document.body ).on( 'change', '#woocommerce_free_shipping_requires', function() {
				wcFreeShippingShowHideMinAmountField( this );
			});

			// Change while load.
			$( '#woocommerce_free_shipping_requires' ).trigger( '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 ) );
				}
			} );
		});"
	);
}