Phone Number Field for the Shipping Address
Adds a phone field to the classic checkout's shipping address, so couriers can reach the recipient when an order is sent to someone else.
Opens WPIDE on
Code
$wpide_shipping_phone_required = false; // Make the recipient phone required.
add_filter( 'woocommerce_shipping_fields', function ( $fields ) use ( $wpide_shipping_phone_required ) {
if ( ! isset( $fields['shipping_phone'] ) ) {
$fields['shipping_phone'] = array(
'label' => 'Recipient phone',
'type' => 'tel',
'required' => $wpide_shipping_phone_required,
'class' => array( 'form-row-wide' ),
'validate' => array( 'phone' ),
'autocomplete' => 'shipping tel',
'priority' => 95,
);
}
return $fields;
} );
Notes
Uses WooCommerce's own shipping_phone order field, so it appears on the order screen and in exports automatically.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.