mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-06 18:16:38 +08:00
Get phone country code from billing country code
This commit is contained in:
parent
72efcbb71d
commit
6c216ad7bb
2 changed files with 11 additions and 25 deletions
|
@ -105,18 +105,8 @@ class PayUponInvoice {
|
||||||
'billing_birth_date',
|
'billing_birth_date',
|
||||||
array(
|
array(
|
||||||
'type' => 'date',
|
'type' => 'date',
|
||||||
'label' => __('Birth date', 'woocommerce-paypal-payments'),
|
'label' => __( 'Birth date', 'woocommerce-paypal-payments' ),
|
||||||
'class' => array('form-row-wide'),
|
'class' => array( 'form-row-wide' ),
|
||||||
'required' => true,
|
|
||||||
'clear' => true,
|
|
||||||
)
|
|
||||||
);
|
|
||||||
woocommerce_form_field(
|
|
||||||
'phone_country_code',
|
|
||||||
array(
|
|
||||||
'type' => 'number',
|
|
||||||
'label' => __('Phone country code (ex. 49)', 'woocommerce-paypal-payments'),
|
|
||||||
'class' => array('form-row-wide'),
|
|
||||||
'required' => true,
|
'required' => true,
|
||||||
'clear' => true,
|
'clear' => true,
|
||||||
)
|
)
|
||||||
|
@ -136,18 +126,14 @@ class PayUponInvoice {
|
||||||
);
|
);
|
||||||
|
|
||||||
add_action(
|
add_action(
|
||||||
'woocommerce_checkout_order_processed',
|
'woocommerce_after_checkout_validation',
|
||||||
function( $order_id, $posted_data, $order ) {
|
function( $fields, $errors ) {
|
||||||
if ( $order->get_billing_country() !== 'DE' ) {
|
if ( $fields['billing_country'] !== 'DE' ) {
|
||||||
wp_send_json_error(
|
$errors->add( 'validation', __( 'Billing country not available.', 'woocommerce-paypal-payments' ) );
|
||||||
array(
|
|
||||||
'result' => 'failure',
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
10,
|
10,
|
||||||
3
|
2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ class PaymentSourceFactory {
|
||||||
public function from_wc_order( WC_Order $order ) {
|
public function from_wc_order( WC_Order $order ) {
|
||||||
$address = $order->get_address();
|
$address = $order->get_address();
|
||||||
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
|
$birth_date = filter_input( INPUT_POST, 'billing_birth_date', FILTER_SANITIZE_STRING );
|
||||||
$phone_country_code = filter_input( INPUT_POST, 'phone_country_code', FILTER_SANITIZE_STRING );
|
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] ?? '' );
|
||||||
|
|
||||||
return new PaymentSource(
|
return new PaymentSource(
|
||||||
$address['first_name'] ?? '',
|
$address['first_name'] ?? '',
|
||||||
|
@ -17,7 +17,7 @@ class PaymentSourceFactory {
|
||||||
$address['email'] ?? '',
|
$address['email'] ?? '',
|
||||||
$birth_date ?? '',
|
$birth_date ?? '',
|
||||||
$address['phone'] ?? '',
|
$address['phone'] ?? '',
|
||||||
$phone_country_code ?? '',
|
substr($phone_country_code, strlen('+')) ?? '',
|
||||||
$address['address_1'] ?? '',
|
$address['address_1'] ?? '',
|
||||||
$address['city'] ?? '',
|
$address['city'] ?? '',
|
||||||
$address['postcode'] ?? '',
|
$address['postcode'] ?? '',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue