Limiting Countries List
-
I’m attempting to filter the countries in the dropdown to just the US and Canada. For now I’m just editing the “em-functions.php” file directly, which works, but I’d like to contain this all in a snippet (care of the Code Snippets plugin) so that it becomes update-proof. I have the following snippet ready:
add_filter('em_get_countries','country_select'); function country_select(){ $em_countries_array = array("US" => "United States", "CA" => "Canada"); if( !is_array($em_countries_array) ){ $em_countries_array_i18n = array(); $em_countries_array_i18n['cs'] = array ('US' => 'Spojené státy', 'CA' => 'Kanada'); $em_countries_array_i18n['da'] = array ('US' => 'USA', 'CA' => 'Canada'); $em_countries_array_i18n['es'] = array ('US' => 'Estados Unidos', 'CA' => 'Canadá'); $em_countries_array_i18n['fr'] = array ('US' => 'états-Unis', 'CA' => 'Canada'); $em_countries_array_i18n['de'] = array ('US' => 'Vereinigte Staaten', 'CA' => 'Kanada'); $em_countries_array_i18n['hu'] = array ('US' => 'Egyesült államok', 'CA' => 'Kanada'); $em_countries_array_i18n['it'] = array ('US' => 'Stati Uniti', 'CA' => 'Canada'); $em_countries_array_i18n['nl'] = array ('US' => 'Verenigde Staten', 'CA' => 'Canada'); $em_countries_array_i18n['pt'] = array ('US' => 'Estados Unidos', 'CA' => 'Canadá'); $em_countries_array_i18n['ru'] = array ('US' => 'США', 'CA' => 'Канада'); $em_countries_array_i18n['sv'] = array ('US' => 'F?renta staterna', 'CA' => 'Kanada'); $em_countries_array_i18n['en'] = array ('US' => 'United States', 'CA' => 'Canada'); $em_countries_array_i18n['fi'] = array ('US' => 'Yhdysvallat', 'CA' => 'Kanada'); $lang = substr(get_locale(), 0, 2); if( array_key_exists($lang, $em_countries_array_i18n) ){ $em_countries_array = $em_countries_array_i18n[$lang]; }else{ $em_countries_array = $em_countries_array_i18n['en']; } } if($sort){ asort($em_countries_array); } if($add_blank !== false){ if(is_array($add_blank)){ $em_countries_array = $add_blank + $em_countries_array; }else{ $em_countries_array = array(0 => $add_blank) + $em_countries_array; } } return apply_filters('em_get_countries', $em_countries_array); }
Alas it’s not yielding the results I’m looking for. Any hints? Thank you.
Viewing 14 replies - 1 through 14 (of 14 total)
Viewing 14 replies - 1 through 14 (of 14 total)
- The topic ‘Limiting Countries List’ is closed to new replies.