I’m surprised WooCommerce doesn’t offer this field out of the box. Most ecommerce websites actually require a shipping phone to organize delivery and communicate with the end customer in case there are problems.
Thankfully, there is a hook (filter) for that. It’s called “woocommerce_checkout_fields” and can be used to remove, move or add checkout fields quickly. And here’s how to add, for example, a new shipping field called “shipping_phone”. Enjoy!
PHP Snippet: Display Shipping Phone @ Checkout Fields
/**
* @snippet Shipping Phone & Email - WooCommerce
* @how-to Get CustomizeWoo.com FREE
* @author Rodolfo Melogli
* @compatible WooCommerce 6
* @community https://businessbloomer.com/club/
*/
add_filter( 'woocommerce_checkout_fields', 'bbloomer_shipping_phone_checkout' );
function bbloomer_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', 'bbloomer_shipping_phone_checkout_display' );
function bbloomer_shipping_phone_checkout_display( $order ){
echo '<p><b>Shipping Phone:</b> ' . get_post_meta( $order->get_id(), '_shipping_phone', true ) . '</p>';
}
Hello,
Thanks for the code. However I believe it would be better to use “woocommerce_shipping_fields” filter to add new field. With this filter new phone filed will be added to the forms under customers’ “/my-account/edit-address” page
Thanks for your feedback!
Thanks! I just added the snippet to my website and it works great.
Quick question – is there a way to make it mandatory (rather than optional)?
Thanks!
Great! Try with ‘required’ => true
Just added this and works great. Thank you
Yay
This is great. Can you tweak it a bit to behave more like the billing phone field where only numbers, brackets and dashes are allowed? I tried setting the type as ‘tel’ with no luck. I also tried ‘number’ but I’m not getting it to quite matchup to the billing phone field.
Thanks for your feedback, Anan. Changed the snippet a little, check it out
Hi,
Thanks a lot for the snippet! It works great.
Cool
Hi there,
Thanks a lot for the snippet! It works like a charm.
Is there a way to get the phone number in emails as well? is there a short code for it? Am trying to add it to my email customizer builder.
Hi Najm, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
adding phone in the email should be part of this. Come on Rodolfo, you’ll be charging 100 USD just to show us how to do this?
I have this already in other snippets on this same site: https://www.businessbloomer.com/woocommerce-add-custom-checkout-field-php/ (part 3).
As you can see, I share all my knowledge for free, so I charge only when the customer has no time or knowledge. You simply had to do a search on Business Bloomer, but it seems you didn’t have the time lol
I just added this and it still works ๐
Great!
Thanks! I love your website – I learned a lot from your code snippets and started always looking for code-snippet solutions instead of adding plugins for everything!
I added this code and it shows up correctly in the checkout page. How to add a second field (shipping email for example) in addition to the first field?
Hello Judith, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
congratulations for the code and thanks. Is it possible to make the field editable from backend? because when I have to add orders manually I can’t enter the number
Hi Gabriele, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi,
I’m Nani.
I’ve added this kind of thing, but somehow now showing the phone number in email.
How to solve that?
Thanks.
Hi Nani, I don’t fully understand. Can you provide a screenshot please?
I guess the question was how to have the recipient’s phone visible in the new order email (shipping address details) – there should be a line of code that adds shipping phone number in the new order email template.
Ah, gotcha. Yes, that’s a complex yet doable customization
Thank you! This still works, however the shipping fields end up misaligned with the billing fields since the Shipping Phone is inserted after the Name instead of after the Zip. The example given at https://docs.woocommerce.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/ has a cleaner implementation.
Thank you!
Thank you Rodolfo,
code is working, text field is added in checkout page, is present in the order in the back office, but is not returned in the “Thank you for your order” email
Grazie
Mauro
Correct, Mauro. Try studying this: https://businessbloomer.com/woocommerce-add-custom-checkout-field-php/ (part #5 snippet #2)