JQuery help after country selection
-
I need to phone number field to be required only if a customer is outside of the UK and I’ve got that working using
add_filter( 'woocommerce_billing_fields', 'wc_npr_filter_phone', 10, 1 ); function wc_npr_filter_phone( $address_fields ) { $wc = WC(); $country = $wc->customer->get_country(); if($country !== 'GB'){ $address_fields['billing_phone']['required'] = true; } return $address_fields; }
So now ‘all’ I need to do now is get the CSS updated via javascript I presume…
I’ve got a child theme with an enqueued js file and to start with all I want it to do is when I click the country dropdown box (or even better when it changes) I want an alert to popup but struggling to get this to work.
I had thought something like the code below would work but not getting anything…
jquery( "#select2-billing_country-container" ).change(function() { alert( "Test" ); });
After I’ve got that bit working then I want to get the country selected from the dropdown box so that it will be something along the lines of
if (#select2-billing_country-container".text()==="United Kingdom (UK)" ) { jQuery("#billing_phone_field > label > abbr").hide(); } else { jQuery("#billing_phone_field > label > abbr").show(); }
Many thanks,
Andrew
The page I need help with: [log in to see the link]
- The topic ‘JQuery help after country selection’ is closed to new replies.