Home / Archive / MemberPress: Add/Override State Drop Down Values
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add/Override State Drop Down Values

Adding this code snippet to a website will override the list of states available under the States dropdown on the MemberPress registration forms. The example below allows modification of the list of states for the United States.

Once the code snippet is added, a PHP file containing the state list needs to be added/adjusted. The file path is /wp-content/plugins/mepr-i18n/states (manually create any folders that might be missing in the path). Below is the example of how the US.php file should be formatted (includes notes on what to change):

/**
* United States
*/

//The lines that follow are the two character code for the given state and the name that will be displayed in the drop down box.

//Remove any unneeded lines (do not remove the last line with the closing parenthesis and semicolon). The last entry should not have a comma at the end.
$states['US'] = array(
'AL' => _x('Alabama', 'ui', 'memberpress'),
'AK' => _x('Alaska', 'ui', 'memberpress'),
'AZ' => _x('Arizona', 'ui', 'memberpress'),
'AR' => _x('Arkansas', 'ui', 'memberpress'),
'CA' => _x('California', 'ui', 'memberpress'),
'CO' => _x('Colorado', 'ui', 'memberpress'),
'CT' => _x('Connecticut', 'ui', 'memberpress'),
'DE' => _x('Delaware', 'ui', 'memberpress'),
'DC' => _x('District Of Columbia', 'ui', 'memberpress'),
'FL' => _x('Florida', 'ui', 'memberpress'),
'GA' => _x( 'Georgia', 'US state of Georgia', 'memberpress' ),
'HI' => _x('Hawaii', 'ui', 'memberpress'),
'ID' => _x('Idaho', 'ui', 'memberpress'),
'IL' => _x('Illinois', 'ui', 'memberpress'),
'IN' => _x('Indiana', 'ui', 'memberpress'),
'IA' => _x('Iowa', 'ui', 'memberpress'),
'KS' => _x('Kansas', 'ui', 'memberpress'),
'KY' => _x('Kentucky', 'ui', 'memberpress'),
'LA' => _x('Louisiana', 'ui', 'memberpress'),
'ME' => _x('Maine', 'ui', 'memberpress'),
'MD' => _x('Maryland', 'ui', 'memberpress'),
'MA' => _x('Massachusetts', 'ui', 'memberpress'),
'MI' => _x('Michigan', 'ui', 'memberpress'),
'MN' => _x('Minnesota', 'ui', 'memberpress'),
'MS' => _x('Mississippi', 'ui', 'memberpress'),
'MO' => _x('Missouri', 'ui', 'memberpress'),
'MT' => _x('Montana', 'ui', 'memberpress'),
'NE' => _x('Nebraska', 'ui', 'memberpress'),
'NV' => _x('Nevada', 'ui', 'memberpress'),
'NH' => _x('New Hampshire', 'ui', 'memberpress'),
'NJ' => _x('New Jersey', 'ui', 'memberpress'),
'NM' => _x('New Mexico', 'ui', 'memberpress'),
'NY' => _x('New York', 'ui', 'memberpress'),
'NC' => _x('North Carolina', 'ui', 'memberpress'),
'ND' => _x('North Dakota', 'ui', 'memberpress'),
'OH' => _x('Ohio', 'ui', 'memberpress'),
'OK' => _x('Oklahoma', 'ui', 'memberpress'),
'OR' => _x('Oregon', 'ui', 'memberpress'),
'PA' => _x('Pennsylvania', 'ui', 'memberpress'),
'RI' => _x('Rhode Island', 'ui', 'memberpress'),
'SC' => _x('South Carolina', 'ui', 'memberpress'),
'SD' => _x('South Dakota', 'ui', 'memberpress'),
'TN' => _x('Tennessee', 'ui', 'memberpress'),
'TX' => _x('Texas', 'ui', 'memberpress'),
'UT' => _x('Utah', 'ui', 'memberpress'),
'VT' => _x('Vermont', 'ui', 'memberpress'),
'VA' => _x('Virginia', 'ui', 'memberpress'),
'WA' => _x('Washington', 'ui', 'memberpress'),
'WV' => _x('West Virginia', 'ui', 'memberpress'),
'WI' => _x('Wisconsin', 'ui', 'memberpress'),
'WY' => _x('Wyoming', 'ui', 'memberpress'),
'AA' => _x('Armed Forces (AA)', 'ui', 'memberpress'),
'AE' => _x('Armed Forces (AE)', 'ui', 'memberpress'),
'AP' => _x('Armed Forces (AP)', 'ui', 'memberpress'),
'AS' => _x('American Samoa', 'ui', 'memberpress'),
'GU' => _x('Guam', 'ui', 'memberpress'),
'MP' => _x('Northern Mariana Islands', 'ui', 'memberpress'),
'PR' => _x('Puerto Rico', 'ui', 'memberpress'),
'UM' => _x('US Minor Outlying Islands', 'ui', 'memberpress'),
'VI' => _x('US Virgin Islands', 'ui', 'memberpress') //No comma on the last entry
); //Do not remove this line

You can apply this code snippet to other countries that also have states/provinces. For example, if you want to apply this code for Canada (CA), the file would look like this:

/**
* Canada
*/
// Change 'CA' to match the two character country code for the country the . Must match the code in wp-content/plugins/memberpress/i18n/countries.php

// The lines that follow are the two character code for the given province/territory and the name that will be displayed in the drop down box.

// Remove any unneeded lines (do not remove the last line with the closing parenthesis and semicolon). The last entry should not have a comma at the end.
$states['CA'] = array(
'AB' => _x('Alberta', 'ui', 'memberpress'),
'BC' => _x('British Columbia', 'ui', 'memberpress'),
'MB' => _x('Manitoba', 'ui', 'memberpress'),
'NB' => _x('New Brunswick', 'ui', 'memberpress'),
'NL' => _x('Newfoundland and Labrador', 'ui', 'memberpress'),
'NS' => _x('Nova Scotia', 'ui', 'memberpress'),
'ON' => _x('Ontario', 'ui', 'memberpress'),
'PE' => _x('Prince Edward Island', 'ui', 'memberpress'),
'QC' => _x('Quebec', 'ui', 'memberpress'),
'SK' => _x('Saskatchewan', 'ui', 'memberpress'),
'NT' => _x('Northwest Territories', 'ui', 'memberpress'),
'NU' => _x('Nunavut', 'ui', 'memberpress'),
'YT' => _x('Yukon', 'ui', 'memberpress') // No comma on the last entry
); // Do not remove this line

Code Preview
php
<?php
function mepr_change_state_dropdown_values ( $states ) {
  $sfiles = @glob( WP_PLUGIN_DIR . '/mepr-i18n/states/[A-Z][A-Z].php', GLOB_NOSORT );
  foreach( $sfiles as $sfile ) {
    require( $sfile );
  }	
  return $states;
}
add_filter( 'mepr_states', 'mepr_change_state_dropdown_values' );

Comments

Add a Comment