Adjust calling code prefix logic in paypal

This commit is contained in:
Mike Jolley 2019-03-06 12:33:46 +00:00
parent 65c0169726
commit 55b27a2afc
2 changed files with 9 additions and 3 deletions

View File

@ -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' );

View File

@ -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,