admin管理员组文章数量:1279207
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');
}
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');
}
Share
Improve this question
edited Nov 11, 2021 at 15:52
RawalD
asked Nov 11, 2021 at 14:13
RawalDRawalD
1214 bronze badges
11
|
Show 6 more comments
1 Answer
Reset to default 1The file was reading from parent theme directory not the child theme directory thus the issue of it not being read.
Found it from tracing the directory from the Network tab
本文标签: formsjQuery will not work on page from snippet or file
版权声明:本文标题:forms - jQuery will not work on page from snippet or file 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741223764a2361470.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
jQuery(document).on('change', '#billing_test'
... – Peter Petrov Commented Nov 11, 2021 at 14:37