I\'ve been banging my head against the wall on this, My jQuery code runs perfect in CodePen, the WP site in console also runs it perfect, however I simply can not get it to run on the actual WooCommerce My Account Billing Address page no matter what.
My jQuery:
jQuery(document).ready(function () {
// Your code in here
jQuery(\'#billing_test\').on(\'change\', function () {
myFunc();
})
function myFunc() {
// your function code
var complex_name = jQuery(\'#billing_test\').val();
var suburb = jQuery(\'#billing_suburb\').val();
if (complex_name == \'mr\') {
alert(\'works\');
jQuery("#billing_suburb").val(\'LDM\');
jQuery(\'#billing_postcode\').val(\'5000\');
}
}
})
I\'ve tried adding via Code Snippets to no luck so tried a script file with the following code:
function my_theme_scripts() {
wp_enqueue_script( \'test\', get_template_directory_uri() . \'/js/test.js\', array( \'jquery\' ) );
}
add_action( \'wp_enqueue_scripts\', \'my_theme_scripts\' );
But still nothing. Any and all help will be really grateful as I\'ve attempted everything I could but still nothing.
I have also tried replacing the $
with jQuery
, tried the $.noConflict()
as well.
Added script manually and it is in the inspect as well.
HTML
<p class="form-row my-css" id="billing_test_field" data-priority=""><label for="billing_test" class="">Test</label><span
class="woocommerce-input-wrapper"><select name="billing_test" id="billing_test" class="select "
data-allow_clear="true" data-placeholder="Title">
<option value="">Please select</option>
<option value="mr">Mr</option>
<option value="ms" selected=\'selected\'>Ms</option>
</select></span></p>
How do I not use if and else if to match the conditions:
if (complex_name == \'eldogleneast\') {
jQuery("#billing_suburb").val(\'ELD\');
jQuery(\'#billing_postcode\').val(\'0157\');
}
else if (complex_name == \'eldoglen\'){
jQuery("#billing_suburb").val(\'ELD\');
jQuery(\'#billing_postcode\').val(\'0157\');
}