diff --git a/includes/class-wc-countries.php b/includes/class-wc-countries.php index 71da82dae52..e8375a983e5 100644 --- a/includes/class-wc-countries.php +++ b/includes/class-wc-countries.php @@ -95,7 +95,7 @@ class WC_Countries { * * @since 3.6.0 * @param string $cc Country code. - * @return string + * @return string|array Some countries have multiple. The code will be stripped of - and spaces and always be prefixed with +. */ public function get_country_calling_code( $cc ) { $codes = wp_cache_get( 'calling-codes', 'countries' ); 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 b39a3bf4764..2cf02c6d4d6 100644 --- a/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php +++ b/includes/gateways/paypal/includes/class-wc-gateway-paypal-request.php @@ -216,8 +216,9 @@ class WC_Gateway_Paypal_Request { * @return array */ protected function get_phone_number_args( $order ) { + $phone_number = str_replace( array( '(', '-', ' ', ')', '.' ), '', $order->get_billing_phone() ); + if ( in_array( $order->get_billing_country(), array( 'US', 'CA' ), true ) ) { - $phone_number = str_replace( array( '(', '-', ' ', ')', '.' ), '', $order->get_billing_phone() ); $phone_number = ltrim( $phone_number, '+1' ); $phone_args = array( 'night_phone_a' => substr( $phone_number, 0, 3 ), @@ -226,7 +227,12 @@ class WC_Gateway_Paypal_Request { ); } else { $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(); + $calling_code = is_array( $calling_code ) ? $calling_code[0] : $calling_code; + + if ( $calling_code ) { + $phone_number = str_replace( $calling_code, '', preg_replace( '/^0/', '', $order->get_billing_phone() ) ); + } + $phone_args = array( 'night_phone_a' => $calling_code, 'night_phone_b' => $phone_number,