
In a recent Business Bloomer Club discussion, a user faced a challenge with WooCommerce’s country dropdown on a Bulgarian-language site. While the checkout country field displayed country names in Bulgarian by default, international customers needed to search using English names, creating a usability gap.
The user sought a way to add English names alongside Bulgarian in the dropdown, allowing search functionality for both languages.
Through a collaboration in the forum, the user leveraged the woocommerce_countries_allowed_countries
filter to display country names in both Bulgarian and English. By setting up an array of English country names and merging them with the default Bulgarian names, they successfully enabled bilingual search functionality in the country dropdown.
Code Solution:
The final code snippet adds English names within parentheses alongside Bulgarian country names, as shown below:
function english_billing_country_dropdown($countries) {
// Define an array with English country names
$english_countries = array(
'AF' => 'Afghanistan',
'AL' => 'Albania',
// ... (other countries)
'ZW' => 'Zimbabwe',
);
foreach ($countries as $code => $name) {
$english_name = isset($english_countries[$code]) ? $english_countries[$code] : $name;
$countries[$code] = $name . ' (' . $english_name . ')';
}
return $countries;
}
add_filter('woocommerce_countries_allowed_countries', 'english_billing_country_dropdown');
Results
With this solution:
- Dual-Language Support: Both Bulgarian and English country names are shown in the dropdown.
- Improved Search Functionality: Customers can search using either language, enhancing usability for international shoppers.
This straightforward customization empowers stores catering to diverse audiences, making checkout navigation smoother for all users.