woocommerce add custom checkout field to email
You should use 'My Field' instead of my_field. As you have saved the custom field with this key. This will definitely solve your problem.
I had similar trouble of printing the result until I added an underscore before 'my_field'.
So use
add_filter('woocommerce_email_order_meta_keys', 'my_custom_checkout_field_order_meta_keys');function my_custom_checkout_field_order_meta_keys( $keys ) { $keys[] = '_my_field'; return $keys;}
it seems when woocommerce is querying the meta data for use in admin section, an underscore is added. So for a field you created as
add_filter( 'woocommerce_checkout_fields' , 'brown_remove_billing_postcode_checkout' );function brown_remove_billing_postcode_checkout( $fields ) { // Add New Fields $fields['billing']['billing_delivery_date'] = array( 'label' => __('Delivery Date', 'woocommerce'), 'placeholder' => _x('yyyy-mm-dd', 'placeholder', 'woocommerce'), 'required' => true, 'class' => array('form-row-wide'), 'clear' => true, 'autocomplete' => false );//Update the order meta with field value. Don't miss the underscore before _b$fields['billing_delivery_date'] = get_post_meta( $order->id, '_billing_delivery_date', true ); return $fields;}
You need to add to your functions.php
/*---------------------------------------------- Add Delivery Date Field to the order emails-------------------------------------------------*/add_filter('woocommerce_email_order_meta_keys', 'my_woocommerce_email_order_meta_keys');function my_woocommerce_email_order_meta_keys( $keys ) { $keys['Delivery Date'] = '_billing_delivery_date'; return $keys; }