WC_Countries::get_country_from_alpha_3_code
Searches for a valid ISO 3166-1 alpha-2 code using the provided alpha-3 code.
Метод класса: WC_Countries{}
Хуков нет.
Возвращает
Строку|null. The alpha-2 country code, or null if not found.
Использование
$WC_Countries = new WC_Countries(); $WC_Countries->get_country_from_alpha_3_code( $country_code );
- $country_code(строка) (обязательный)
- The alpha-3 country code to search for.
Список изменений
| С версии 10.3.0 | Введена. |
Код WC_Countries::get_country_from_alpha_3_code() WC Countries::get country from alpha 3 code WC 10.5.2
public function get_country_from_alpha_3_code( $country_code ) {
// Validate input.
if ( empty( $country_code ) || ! is_string( $country_code ) ) {
return null;
}
try {
$data = ( new Automattic\WooCommerce\Vendor\League\ISO3166\ISO3166() )->alpha3( $country_code );
if ( ! isset( $data['alpha2'] ) ) {
throw new \Exception( 'Alpha-2 country code not found for alpha-3 code.' );
}
// Return the alpha-2 code.
return $data['alpha2'];
} catch ( \Exception $e ) {
return null;
}
}