Home / Archive / MemberPress: Set Default Country on Registration Page
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Set Default Country on Registration Page

This code will help set specified country as default country for the Country field on MemberPress regisatrtion pages.

The sample code will set United States as the default country.

To change the country, the two-letter code (Alpha-2 code) for United States "US" should be changed to the two-letter code of the desired country on this line:

countryDropdown.val('US');

The two-letter country ISO codes (Alpha-2 code) are available here: https://www.iso.org/obp/ui/#search

Code Preview
php
<?php
function mepr_set_default_country_script() {
    ?>
    <script type="text/javascript">
        jQuery(document).ready(function($) {
            var countryDropdown = $('#mepr-address-country');
            if (countryDropdown.length > 0) {
                countryDropdown.val('US');
            }
        });
    </script>
    <?php
}
add_action('wp_footer', 'mepr_set_default_country_script');

Comments

Add a Comment