Support

Home Forums Event Espresso Premium Default country with default states

Default country with default states

Posted: February 14, 2021 at 8:45 pm

Viewing 3 reply threads


jaybe

February 14, 2021 at 8:45 pm

I added the following code found here to the functions.php file to show the US as default country on oure reg form. But I also need the states list to default to the US states as well. Or, even better, to only show states that are applicable to the chosen country. Right now, it’s endless scrolling on the states list to get to the US to choose a state. Can you provide something to help us with this?
Thank you.

add_action(
‘wp_enqueue_scripts’,
‘my_change_default_ee_country_option’,
20
);
function my_change_default_ee_country_option(){
$custom_js = ‘jQuery(document).ready(function($){‘;
$custom_js .= ‘$(“.ee-reg-qstn-country”).val(“US”);’;
$custom_js .= ‘});’;
wp_add_inline_script(‘ee_form_section_validation’, $custom_js);
}


Tony

  • Support Staff

February 16, 2021 at 6:18 am

Hi there,

That’s actually exactly what happens if you manually select a Country, the other ‘states’ are filtered out of the state options.

However, with the above code setting the value using .val() doesn’t trigger the change event EE uses to do this, so that needs to be called manually.

Change:

$custom_js .= '$(".ee-reg-qstn-country").val("US");';

To this:

$custom_js .= '$(".ee-reg-qstn-country").val("US").trigger("change");';

Does it work then?


jaybe

February 16, 2021 at 9:17 am

That took care of it – thank you so much!


Tony

  • Support Staff

February 16, 2021 at 9:18 am

You’re most welcome.

Viewing 3 reply threads

The support post ‘Default country with default states’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso