Add phone number to my account shipping address. (#47062)

* Added phone number support to Shipping Address and refactor the code.

* Refactored to avoid evaluating extra if on !== billing address form

* Add changefile(s) from automation for the following project(s): woocommerce

* Fixed tests.

* Mock phone number consistency
This commit is contained in:
Paulo Arromba 2024-05-13 12:48:57 +01:00 committed by GitHub
parent 69daa61877
commit 4840af874a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 30 additions and 16 deletions

View File

@ -0,0 +1,4 @@
Significance: minor
Type: add
Added phone number field to Shipping Address form under My Account

View File

@ -1695,12 +1695,15 @@ class WC_Countries {
$address_fields[ $type . $key ] = $value;
}
// Add email and phone fields.
if ( 'billing_' === $type ) {
if ( 'hidden' !== get_option( 'woocommerce_checkout_phone_field', 'required' ) ) {
$address_fields['billing_phone'] = array(
// Add fields to address forms.
if ( in_array( $type, array( 'billing_', 'shipping_' ), true ) ) {
// Add phone to billing/shipping address form.
$show_phone_field = get_option( 'woocommerce_checkout_phone_field', 'required' );
if ( 'hidden' !== $show_phone_field ) {
$address_fields[ $type . 'phone' ] = array(
'label' => __( 'Phone', 'woocommerce' ),
'required' => 'required' === get_option( 'woocommerce_checkout_phone_field', 'required' ),
'required' => 'required' === $show_phone_field,
'type' => 'tel',
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
@ -1708,15 +1711,19 @@ class WC_Countries {
'priority' => 100,
);
}
$address_fields['billing_email'] = array(
'label' => __( 'Email address', 'woocommerce' ),
'required' => true,
'type' => 'email',
'class' => array( 'form-row-wide' ),
'validate' => array( 'email' ),
'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
'priority' => 110,
);
// Add email to billing address form.
if ( 'billing_' === $type ) {
$address_fields['billing_email'] = array(
'label' => __( 'Email address', 'woocommerce' ),
'required' => true,
'type' => 'email',
'class' => array( 'form-row-wide' ),
'validate' => array( 'email' ),
'autocomplete' => 'no' === get_option( 'woocommerce_registration_generate_username' ) ? 'email' : 'email username',
'priority' => 110,
);
}
}
/**

View File

@ -966,7 +966,7 @@ test.describe.serial( 'Tax rates in the cart and checkout', () => {
.getByRole( 'textbox', { name: 'ZIP Code *' } )
.type( customer.billing.us.zip );
await page
.getByLabel( 'Phone *' )
.getByRole( 'textbox', { name: 'Phone *' } )
.fill( customer.billing.us.phone );
await page
.getByLabel( 'Email address *' )

View File

@ -333,7 +333,9 @@ test.describe( 'Checkout page', () => {
await page
.getByRole( 'textbox', { name: 'ZIP Code *' } )
.fill( '97403' );
await page.getByLabel( 'Phone *' ).fill( '555 555-5555' );
await page
.getByRole( 'textbox', { name: 'Phone *' } )
.fill( '555 555-5555' );
await page.getByLabel( 'Email address *' ).fill( guestEmail );
await page.getByText( 'Cash on delivery' ).click();

View File

@ -108,6 +108,7 @@ test.describe( 'Customer can manage addresses in My Account > Addresses page', (
await page.locator( '#shipping_country' ).selectOption( 'US' );
await page.locator( '#shipping_state' ).selectOption( 'NY' );
await page.locator( '#shipping_postcode' ).fill( '10010' );
await page.locator( '#shipping_phone' ).fill( '555 555-5555' );
await page.locator( 'text=Save address' ).click();
// verify shipping address has been applied