You are currently viewing Add custom email and phone in shipping address at WooCommerce checkout

Add custom email and phone in shipping address at WooCommerce checkout

Woocommerce doesn’t provide email address and phone no to shipping address of checkout page. When we select shipping address is different from billing, then sometimes it’s needed insert contact no and email address to contact customer easily for delivering order. Place the below code in function.php of themes and you will find email address and phone no added in checkout shipping address form.

add_filter( 'woocommerce_checkout_fields' , 'woocommerce_checkout_field_editor' );
function woocommerce_checkout_field_editor( $fields ) {
    $fields['shipping']['shipping_phone'] = array(
        'label'     => __('Phone', 'woocommerce'),
        'required'  => true,
	'type' => 'tel',
	'class' => array(
	      'form-row-wide'
	) ,
	'validate' => array(
              'phone'
	) ,
	'autocomplete' => 'tel',
	'priority' => 100
    );
	
    $fields['shipping']['shipping_email'] = array(
        'label'     => __('Email address', 'woocommerce'),       
        'required'  => true,
	'type' => 'email',
	'class' => array(
             'form-row-wide'
	) ,
	'validate' => array(
	     'email'
	) ,
	'autocomplete' => 'email',
	'priority' => 110
		
    );
    return $fields;
}

Once fields is added to checkout form, you can feel up the details and after placing order the data is stored in database. Now its time to display that data in backend of detailed order. Place below code in function.php of theme and you will be able to see contact no and email address in order details.

add_action( 'woocommerce_admin_order_data_after_shipping_address', 'edit_woocommerce_checkout_page', 10, 1 );

function edit_woocommerce_checkout_page($order){
        global $post_id;
        $order = new WC_Order( $post_id );

	echo '<p><strong>'.__('Email address').':</strong> <a href="mailto:'.get_post_meta($order->get_id(), '_shipping_email', true ).'">' . get_post_meta($order->get_id(), '_shipping_email', true ) . '</a></p>';

	echo '<p><strong>'.__('Phone').':</strong> <a href="tel:'.get_post_meta($order->get_id(), '_shipping_phone', true ).'">' . get_post_meta($order->get_id(), '_shipping_phone', true ) . '</a></p>';
}

Now you can trap contact no and email address in your order details easily.

Leave a Reply