Country Selector

A searchable dropdown of all ISO 3166-1 countries listed alphabetically. The free version returns the two-letter country code. The Pro version adds multi-select, flag emoji display, and additional return formats.

Settings

SettingDefaultOptionsDescription
Return FormatcodecodeFree: always returns the ISO alpha-2 code. Pro adds name, flag, and object.

Return values

return_format: 'code' (free)

Returns the ISO 3166-1 alpha-2 code as a two-letter uppercase string.

$country = get_field('shipping_country');
// "US"  "GB"  "DE"  "JP"

Usage

Displaying the country name

PHP’s Locale extension can expand a code to a human-readable name:

$code = get_field('country');
if ($code) {
    $name = Locale::getDisplayRegion('-' . $code, 'en');
    echo '<span class="country">' . esc_html($name) . '</span>';
    // "United States"
}

Displaying a flag emoji

Convert the ISO code to the regional indicator emoji pair:

function code_to_flag(string $code): string {
    $offset = 0x1F1A5; // Regional Indicator offset
    return mb_chr($offset + ord($code[0])) . mb_chr($offset + ord($code[1]));
}

$code = get_field('country');
if ($code) {
    echo code_to_flag($code) . ' ' . esc_html($code);
    // 🇺🇸 US
}

Filtering posts by country

$posts = get_posts([
    'post_type'  => 'team_member',
    'meta_query' => [[
        'key'   => 'country',
        'value' => 'CA',
    ]],
]);

Using in a contact form context

$code = get_field('billing_country');
$vat_countries = ['DE', 'FR', 'IT', 'ES', 'NL', 'BE', 'AT', 'PL'];

if (in_array($code, $vat_countries, true)) {
    // Show VAT number field
}
i
Pro features

The Pro version adds multi-select, return formats for full country name, flag emoji, or a complete object with code, name, and flag.