Black Friday & Cyber Monday SUPER SALE ALL WEEK:
Grab 40% OFF on plugins
Days
Hours
Minutes
Seconds

How to Add the Shipping Phone number field on the WooCommerce checkout page?

Customers prefer separate phone numbers for billing and shipping because they want shipping-related messages to go to a different contact. Adding the phone number field in the shipping section of the checkout page helps store owners contact the right customer regarding delivery updates. It’s totally the store owner’s choice to make the fields optional or mandatory.

This post guides you well to add the Shipping Phone number field on the WooCommerce checkout page.

Where to Add Custom Code in WooCommerce?

It is advisable to add the code snippets to the functions.php file of your child theme. Access the file directly from Appearance->Theme File Editor->Locating the child theme’s functions.php from the right sidebar. You can also access it from your theme’s directory file. Insert the following code snippet in functions.php. The alternative & easy option is to install & activate the Code Snippets plugin. You can then add the code as a new snippet via the plugin.

Solution: Add the Shipping Phone number field on the WooCommerce checkout page

This code will help to add a phone number field in the Shipping section.

add_filter( 'woocommerce_checkout_fields', 'ts_shipping_phone_checkout' );
 
function ts_shipping_phone_checkout( $fields ) {
   $fields['shipping']['shipping_phone'] = array(
      'label' => 'Phone',
      'type' => 'tel',
      'required' => false,
      'class' => array( 'form-row-wide' ),
      'validate' => array( 'phone' ),
      'autocomplete' => 'tel',
      'priority' => 25,
   );
   return $fields;
}
  
add_action( 'woocommerce_admin_order_data_after_shipping_address', 'ts_shipping_phone_checkout_display' );
 
function ts_shipping_phone_checkout_display( $order ){
    echo '<p><b>Shipping Phone:</b> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
}

Code Output 

Output 1

By default, the phone number field is not available in the “Ship to a different address?” section as shown below.

How to Add the Shipping Phone number field on the WooCommerce checkout page? - Tyche Softwares

Output 2

The following output illustrates that the code adds the Phone number field into the Shipping section on the WooCommerce checkout page.

How to Add the Shipping Phone number field on the WooCommerce checkout page? - Tyche Softwares

Also, the store owner can view this shipping phone number in the WordPress admin area. It will display the shipping phone number associated with that order under a “Shipping Phone:” label. 

How to Add the Shipping Phone number field on the WooCommerce checkout page? - Tyche Softwares

Code Explanation

  1. The code begins with a filter hook woocommerce_checkout_fields, and it’s set to trigger the function ‘ts_shipping_phone_checkout’  when processing the checkout fields in a WooCommerce store.
  2. The function ts_shipping_phone_checkout is defined to modify the checkout fields.
  3. $fields is an array that holds information about the checkout fields.
  4. $fields[‘shipping’][‘shipping_phone’] is used to add a new field in the shipping section of the checkout page.
  5. Properties of the added field:
    • ‘label’ => ‘Phone’: Sets the label for the field as “Phone.”
    • ‘type’ => ‘tel’: Specifies the input field type as ‘tel’, indicating it’s meant for telephone numbers.
    • ‘required’ => false: Makes the phone number field optional (not mandatory).
    • ‘class’ => array( ‘form-row-wide’ ): Applies a CSS class to the field, making it wider to enhance the layout.
    • ‘validate’ => array( ‘phone’ ): Requests validation for a valid phone number.
    • ‘autocomplete’ => ‘tel’: Provides a hint to browsers that this is a telephone number field.
    • ‘priority’ => 25: Sets the display priority of the field.
    • return $fields; ends back the modified field configuration to WooCommerce.
  6. The add_action hook woocommerce_admin_order_data_after_shipping_address triggers the function bbloomer_shipping_phone_checkout_display after displaying the shipping address in the WooCommerce admin area when viewing an order.
  7. The Function ts_shipping_phone_checkout_display is responsible for displaying the shipping phone number associated with an order.
  8. It takes $order as a parameter, representing the order being viewed in the admin area.
  9. echo ‘<p><b>Shipping Phone:</b> ‘ . get_post_meta( $order->get_id(), ‘_shipping_phone’, true ) . ‘</p>’; generates HTML output to display the shipping phone number.
  10. get_post_meta( $order->get_id(), ‘_shipping_phone’, true ) retrieves the shipping phone number from the order’s metadata.
  11. The phone number is displayed in a paragraph (<p>) with the label “Shipping Phone” in bold (<b>).

Conclusion

In the above code, the phone number field is added to the shipping section. You can modify the code to retrieve the shipping phone number associated with the order and include it in the email content using the woocommerce_email_order_details action hook.

Let us know your feedback on how the code was useful or any other queries in the comments section.

Browse more in: Code Snippets, WooCommerce How Tos, WooCommerce Tutorials

Share It:

Subscribe
Notify of
10 Comments
Newest
Oldest
Inline Feedbacks
View all comments
Fumio
2 months ago

Hi Saranya,

Thank you for sharing the code—it works perfectly!

I’m currently trying to add a shipping phone number and its extension to the WooCommerce checkout page. While the phone number field has been added successfully, I’m having trouble displaying the extension number along with the phone number in the shipping address details on the order details page.

Could you please assist me with how to correctly include and display both the phone number and its extension in the shipping address? Any guidance on resolving this issue would be greatly appreciated.

Best regards,

Fumio
2 months ago
Reply to  Fumio

Hi Saranya,

Thank you for the prompt response and for providing the code snippet!
It works perfectly!
To clarify, I initially tried adding the extension number within the same phone field but realized it would be more effective to have it as a separate field, as you suggested. The code you provided makes sense, and I can now see how to add the extension as a distinct field and display it in the order details page. Thank you again for your help!

3 months ago

Hello

Thanks this Code works well! Is there a way to change the position of this field in the Shipping Address section, currently it is just below the Name field and it woudl be good to move it to just below the Post Code field ( same as Billing Address)
Many thanks

3 months ago
Reply to  Saranya

Hello Saranya

Many thanks for the prompt reply and the tweak on the Code – the telephone number field is now in a better place!
Many thanks
Alan

Bansi
8 months ago

https://www.tychesoftwares.com/how-to-add-the-shipping-phone-number-field-on-the-woocommerce-checkout-page/

in this shipping filed i need to add to allow 15 digits user can add Pls guide how i can i have add max length in input type but not working else what i can do?

Screenshot_23
Bansi
8 months ago
Reply to  Saranya

I have already tried it but its not working can u have another solution ?

10
0
Would love your thoughts, please comment.x
()
x