I followed Gary’s advice and links provided and came up with the following code to paste into my functions.php file. I commented out the email parts as I did not want it, I only wanted shipping phone number. So far works great.
/* Add additional shipping fields (email, phone) in FRONT END (i.e. My Account and Order Checkout) */
/* Note: $fields keys (i.e. field names) must be in format: "shipping_" */
add_filter( 'woocommerce_shipping_fields' , 'my_additional_shipping_fields' );
function my_additional_shipping_fields( $fields ) {
/* $fields['shipping_email'] = array(
'label' => __( 'Ship Email', 'woocommerce' ),
'required' => false,
'class' => array( 'form-row-last' ),
'validate' => array( 'email' ),
); */
$fields['shipping_phone'] = array(
'label' => __( 'Ship Phone', 'woocommerce' ),
'required' => false, /* change to true if needs to be required*/
// 'class' => array( 'form-row-first' ), // This will split the area in two columns, works good if email is turned on but with just phone, layout screws up on some screens
'clear' => true,
'validate' => array( 'phone' ),
);
return $fields;
}
/* Display additional shipping fields (email, phone) in ADMIN area (i.e. Order display ) */
/* Note: $fields keys (i.e. field names) must be in format: WITHOUT the "shipping_" prefix (it's added by the code) */
add_filter( 'woocommerce_admin_shipping_fields' , 'my_additional_admin_shipping_fields' );
function my_additional_admin_shipping_fields( $fields ) {
/* $fields['email'] = array(
'label' => __( 'Order Ship Email', 'woocommerce' ),
); */
$fields['phone'] = array(
'label' => __( 'Order Ship Phone', 'woocommerce' ),
);
return $fields;
}
/* Display additional shipping fields (email, phone) in USER area (i.e. Admin User/Customer display ) */
/* Note: $fields keys (i.e. field names) must be in format: shipping_ */
add_filter( 'woocommerce_customer_meta_fields' , 'my_additional_customer_meta_fields' );
function my_additional_customer_meta_fields( $fields ) {
$fields['shipping']['fields']['shipping_phone'] = array(
'label' => __( 'Telephone', 'woocommerce' ),
'description' => '',
); /*
$fields['shipping']['fields']['shipping_email'] = array(
'label' => __( 'Email', 'woocommerce' ),
'description' => '',
); */
return $fields;
}
/* Add CSS for ADMIN area so that the additional shipping fields (email, phone) display on left and right side of edit shipping details */
add_action('admin_head', 'my_custom_admin_css');
function my_custom_admin_css() {
echo '<style>
#order_data .order_data_column ._shipping_phone_field {
clear: left;
float: left;
}
#order_data .order_data_column ._shipping_email_field {
float: right;
}
</style>';
}
/* END additional shipping fields (email, phone) */