Skip to content

Instantly share code, notes, and snippets.

@lorenzocaum
Last active September 19, 2015 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lorenzocaum/8be1acdc17c51234f081 to your computer and use it in GitHub Desktop.
Save lorenzocaum/8be1acdc17c51234f081 to your computer and use it in GitHub Desktop.
How to set a default state/province on the registration checkout page in Event Espresso 4

This sample coding can be added to your child theme’s functions.php file (do not include the opening php tag) or a site specific plugin:

http://eventespresso.com/wiki/create-site-specific-plugin-wordpress-site/

123 should be changed to your page ID of your actual registration checkout page. This can be found by going to your WP dashboard and clicking on the registration checkout WordPress page. The ID appears at the end of the URL.

For example, if the ID for your registration checkout page was 1297, then you should use that value in the sample coding instead of 123.

Next, you'll need to update the value for val. In the example, it is set to 76. You can find the value by inspecting the state/province dropdown using Chrome developer tools, Firebug, Safari developer tools, or another tool. In this screenshot, we see that the value for Australian Capital Territory is 76:

http://cl.ly/image/3h352c2O1D33

Be sure to substitute in the value for the state/province that you would like to use.

Here is another example:

http://cl.ly/image/2u1B1q0Q1K3B

In the screenshot above, we see that Florida has a value of 12. Therefore, if we wanted Florida to be the default state/province, then we would use that value instead of 76 in the sample coding.

Add the sample code below to your child theme's functions.php file or in a site specific plugin.

<?php
//* Do NOT include the opening php tag
 
//* Set a default state/province on the registration checkout page
function ee_default_state_province_registration_checkout() {
    if ( is_page( 123 ) ) {
        ?>
        <script>
        jQuery(document).ready( function($) {
          jQuery("select[id$=state]").val(76);
        });
        </script>
        <?php
    }
}
add_action('wp_head', 'ee_default_state_province_registration_checkout');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment