From 8a1a1d3e736e4cd0a643226ea979a92dcebc7595 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Fri, 8 Feb 2019 11:09:42 +0000 Subject: [PATCH] get_calling_code_for_country --- includes/class-wc-countries.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index 37d4395613b..36d11b674ca 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -90,6 +90,24 @@ class WC_Countries { return ''; } + /** + * Get calling code for a country code. + * + * @since 3.6.0 + * @param string $cc Country code. + * @return string + */ + public function get_calling_code_for_country( $cc ) { + $codes = wp_cache_get( 'calling-codes', 'countries' ); + + if ( ! $codes ) { + $codes = json_decode( file_get_contents( WC()->plugin_path() . '/i18n/phone.json' ), true ); // Data from http://country.io/phone.json. + wp_cache_set( 'calling-codes', $codes, 'countries' ); + } + + return isset( $codes[ $cc ] ) ? $codes[ $cc ] : ''; + } + /** * Get continents that the store ships to. *