Add phone field to pui when is removed from checkout

This commit is contained in:
dinamiko 2022-07-21 14:15:25 +02:00
parent d9a6a89f2c
commit 8b45076412
2 changed files with 23 additions and 3 deletions

View file

@ -322,6 +322,26 @@ class PayUponInvoice {
)
);
$checkout_fields = WC()->checkout()->get_checkout_fields();
if ( ! array_key_exists( 'billing_phone', $checkout_fields['billing'] ) ) {
woocommerce_form_field(
'billing_phone',
array(
/**
* Use translation from WooCommerce here.
* phpcs:disable WordPress.WP.I18n.TextDomainMismatch
*/
'label' => __( 'Phone', 'woocommerce' ),
// phpcs:enable WordPress.WP.I18n.TextDomainMismatch
'type' => 'tel',
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
'autocomplete' => 'tel',
'required' => true,
)
);
}
echo '</div><div>';
// phpcs:ignore WordPress.WP.I18n.TextDomainMismatch

View file

@ -24,8 +24,8 @@ class PaymentSourceFactory {
* @return PaymentSource
*/
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 = 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 ) {
@ -44,7 +44,7 @@ class PaymentSourceFactory {
$address['last_name'] ?? '',
$address['email'] ?? '',
$birth_date,
preg_replace( '/[^0-9]/', '', $address['phone'] ) ?? '',
preg_replace( '/[^0-9]/', '', $phone ) ?? '',
$phone_country_code,
$address['address_1'] ?? '',
$address['city'] ?? '',