WC_Countries::get_country_calling_code
Get calling code for a country code.
Method of the class: WC_Countries{}
No Hooks.
Returns
String|Array. Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +.
Usage
$WC_Countries = new WC_Countries(); $WC_Countries->get_country_calling_code( $cc );
- $cc(string) (required)
- Country code.
Changelog
| Since 3.6.0 | Introduced. |
WC_Countries::get_country_calling_code() WC Countries::get country calling code code WC 10.6.2
public function get_country_calling_code( $cc ) {
$codes = wp_cache_get( 'calling-codes', 'countries' );
if ( ! $codes ) {
$codes = include WC()->plugin_path() . '/i18n/phone.php';
wp_cache_set( 'calling-codes', $codes, 'countries' );
}
$calling_code = isset( $codes[ $cc ] ) ? $codes[ $cc ] : '';
if ( is_array( $calling_code ) ) {
$calling_code = $calling_code[0];
}
return $calling_code;
}