mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-08-30 05:00:51 +08:00
Merge pull request #742 from woocommerce/PCP-799-pui-feature-request-add-option-for-a-phone-number-field-next-to-the-birth-date-field
PUI feature request: add option for a phone number field next to the Birth Date field (799)
This commit is contained in:
commit
79acb04e73
3 changed files with 29 additions and 3 deletions
|
@ -333,6 +333,23 @@ class PayUponInvoice {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$checkout_fields = WC()->checkout()->get_checkout_fields();
|
||||||
|
$checkout_phone_required = $checkout_fields['billing']['billing_phone']['required'] ?? false;
|
||||||
|
if ( ! array_key_exists( 'billing_phone', $checkout_fields['billing'] ) || $checkout_phone_required === false ) {
|
||||||
|
woocommerce_form_field(
|
||||||
|
'billing_phone',
|
||||||
|
array(
|
||||||
|
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
||||||
|
'label' => __( 'Phone', 'woocommerce' ),
|
||||||
|
'type' => 'tel',
|
||||||
|
'class' => array( 'form-row-wide' ),
|
||||||
|
'validate' => array( 'phone' ),
|
||||||
|
'autocomplete' => 'tel',
|
||||||
|
'required' => true,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
echo '</div><div>';
|
echo '</div><div>';
|
||||||
|
|
||||||
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch
|
||||||
|
@ -376,6 +393,9 @@ class PayUponInvoice {
|
||||||
}
|
}
|
||||||
|
|
||||||
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
|
$national_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING );
|
||||||
|
if ( ! $national_number ) {
|
||||||
|
$errors->add( 'validation', __( 'Phone field cannot be empty.', 'woocommerce-paypal-payments' ) );
|
||||||
|
}
|
||||||
if ( $national_number ) {
|
if ( $national_number ) {
|
||||||
$numeric_phone_number = preg_replace( '/[^0-9]/', '', $national_number );
|
$numeric_phone_number = preg_replace( '/[^0-9]/', '', $national_number );
|
||||||
if ( $numeric_phone_number && ! preg_match( '/^[0-9]{1,14}?$/', $numeric_phone_number ) ) {
|
if ( $numeric_phone_number && ! preg_match( '/^[0-9]{1,14}?$/', $numeric_phone_number ) ) {
|
||||||
|
|
|
@ -215,6 +215,12 @@ class PayUponInvoiceGateway extends WC_Payment_Gateway {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$phone_number = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? '';
|
||||||
|
if ( $phone_number ) {
|
||||||
|
$wc_order->set_billing_phone( $phone_number );
|
||||||
|
$wc_order->save();
|
||||||
|
}
|
||||||
|
|
||||||
$wc_order->update_status( 'on-hold', __( 'Awaiting Pay upon Invoice payment.', 'woocommerce-paypal-payments' ) );
|
$wc_order->update_status( 'on-hold', __( 'Awaiting Pay upon Invoice payment.', 'woocommerce-paypal-payments' ) );
|
||||||
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
$purchase_unit = $this->purchase_unit_factory->from_wc_order( $wc_order );
|
||||||
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order, $birth_date );
|
$payment_source = $this->payment_source_factory->from_wc_order( $wc_order, $birth_date );
|
||||||
|
|
|
@ -24,8 +24,8 @@ class PaymentSourceFactory {
|
||||||
* @return PaymentSource
|
* @return PaymentSource
|
||||||
*/
|
*/
|
||||||
public function from_wc_order( WC_Order $order, string $birth_date ) {
|
public function from_wc_order( WC_Order $order, string $birth_date ) {
|
||||||
$address = $order->get_address();
|
$address = $order->get_address();
|
||||||
|
$phone = filter_input( INPUT_POST, 'billing_phone', FILTER_SANITIZE_STRING ) ?? $address['phone'] ?: '';
|
||||||
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
|
$phone_country_code = WC()->countries->get_country_calling_code( $address['country'] );
|
||||||
$phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
|
$phone_country_code = is_array( $phone_country_code ) && ! empty( $phone_country_code ) ? $phone_country_code[0] : $phone_country_code;
|
||||||
if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) {
|
if ( is_string( $phone_country_code ) && '' !== $phone_country_code ) {
|
||||||
|
@ -44,7 +44,7 @@ class PaymentSourceFactory {
|
||||||
$address['last_name'] ?? '',
|
$address['last_name'] ?? '',
|
||||||
$address['email'] ?? '',
|
$address['email'] ?? '',
|
||||||
$birth_date,
|
$birth_date,
|
||||||
preg_replace( '/[^0-9]/', '', $address['phone'] ) ?? '',
|
preg_replace( '/[^0-9]/', '', $phone ) ?? '',
|
||||||
$phone_country_code,
|
$phone_country_code,
|
||||||
$address['address_1'] ?? '',
|
$address['address_1'] ?? '',
|
||||||
$address['city'] ?? '',
|
$address['city'] ?? '',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue