WC_Settings_General::output
Output settings with additional JS to hide preferred provider if autocomplete is disabled.
Method of the class: WC_Settings_General{}
No Hooks.
Returns
null. Nothing (null).
Usage
$WC_Settings_General = new WC_Settings_General(); $WC_Settings_General->output();
WC_Settings_General::output() WC Settings General::output code WC 10.8.1
public function output() {
parent::output();
$handle = 'wc-admin-settings-general';
wp_register_script( $handle, '', array(), WC_VERSION, array( 'in_footer' => true ) );
wp_enqueue_script( $handle );
wp_add_inline_script(
$handle,
"
const preferredProviderInput = document.querySelector( '#woocommerce_address_autocomplete_provider' );
const autocompleteEnabledInput = document.querySelector( '#woocommerce_address_autocomplete_enabled' );
let preferredProviderRow = null;
if ( preferredProviderInput ) {
preferredProviderRow = preferredProviderInput.closest( 'tr' );
}
if ( autocompleteEnabledInput && preferredProviderRow ) {
if ( ! autocompleteEnabledInput.checked ) {
preferredProviderRow.style.display = 'none';
}
autocompleteEnabledInput.addEventListener( 'change', function( e ) {
if ( e.target.checked ) {
preferredProviderRow.style.display = 'table-row';
} else {
preferredProviderRow.style.display = 'none';
}
} );
}
"
);
}