From 4330b2eb3845dcbe0e68d6cfe7c1b6c2ae71759f Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Wed, 6 Mar 2019 12:25:06 +0000 Subject: [PATCH] Update calling code handling --- i18n/phone.php | 1 + includes/class-wc-countries.php | 12 +++++++++--- .../includes/class-wc-gateway-paypal-request.php | 2 +- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/i18n/phone.php b/i18n/phone.php index d06685899a5a1..3f118c971eac8 100644 --- a/i18n/phone.php +++ b/i18n/phone.php @@ -206,6 +206,7 @@ 'DO' => array( '+1809', '+1829', + '+1849', ), 'DM' => '+1767', 'DJ' => '+253', diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index 36d11b674caa8..570f7271dea37 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -97,15 +97,21 @@ public function get_continent_code_for_country( $cc ) { * @param string $cc Country code. * @return string */ - public function get_calling_code_for_country( $cc ) { + public function get_country_calling_code( $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. + $codes = include WC()->plugin_path() . '/i18n/phone.php'; wp_cache_set( 'calling-codes', $codes, 'countries' ); } - return isset( $codes[ $cc ] ) ? $codes[ $cc ] : ''; + $calling_code = isset( $codes[ $cc ] ) ? $codes[ $cc ] : ''; + + if ( is_array( $calling_code ) ) { + $calling_code = $calling_code[0]; + } + + return $calling_code; } /** diff --git a/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php b/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php index bc4d581b5c0b6..99930464c5e3e 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php @@ -210,7 +210,7 @@ protected function get_phone_number_args( $order ) { 'night_phone_c' => substr( $phone_number, 6, 4 ), ); } else { - $calling_code = WC()->countries->get_calling_code_for_country( $order->get_billing_country() ); + $calling_code = WC()->countries->get_country_calling_code( $order->get_billing_country() ); $phone_number = $calling_code ? preg_replace( '/^0/', '', $order->get_billing_phone() ) : $order->get_billing_phone(); $phone_args = array( 'night_phone_a' => $calling_code,