WC_Gateway_Paypal_Request::get_phone_number_args()protectedWC 1.0

Get phone number args for paypal request.

Method of the class: WC_Gateway_Paypal_Request{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_phone_number_args( $order );
$order(WC_Order) (required)
Order object.

WC_Gateway_Paypal_Request::get_phone_number_args() code WC 8.6.1

protected function get_phone_number_args( $order ) {
	$phone_number = wc_sanitize_phone_number( $order->get_billing_phone() );

	if ( in_array( $order->get_billing_country(), array( 'US', 'CA' ), true ) ) {
		$phone_number = ltrim( $phone_number, '+1' );
		$phone_args   = array(
			'night_phone_a' => substr( $phone_number, 0, 3 ),
			'night_phone_b' => substr( $phone_number, 3, 3 ),
			'night_phone_c' => substr( $phone_number, 6, 4 ),
		);
	} else {
		$calling_code = WC()->countries->get_country_calling_code( $order->get_billing_country() );
		$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,
		);
	}
	return $phone_args;
}