title: woocommerce add custom checkout field to email
body: <p><strong>Wordpress - Woocommerce</strong></p>
  
  <p><strong>What I try to do:</strong></p>
  
  <ul>
  <li>Add some custom fields in the Checkout page.</li>
  <li>Also, send the value of these fields to my email when receiving a new order.</li>
  </ul>
  
  <p><strong>This is what I did, but failed:</strong></p>
  
  <p>I follow the tutorial here: <a href="http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/" rel="noreferrer">http://docs.woothemes.com/document/tutorial-customising-checkout-fields-using-actions-and-filters/</a></p>
  
  <p>Everything goes right, I created the fields successfully and they appear in the order setting page:</p>
  
  <pre><code>add_action( 'woocommerce_after_order_notes', 'my_checkout_fields' );
  
  function my_checkout_fields( $checkout ) {
  
  echo '&lt;div id="my_checkout_fields"&gt;&lt;h2&gt;' . __('My Heading') . '&lt;/h2&gt;';
  
  woocommerce_form_field( 'my_field', array(
      'type'      =&gt; 'select',
      'options'   =&gt; array(
          'option_1' =&gt; 'My Option 1',
          'option_2' =&gt; 'My Option 2'
      ),
      'clear'     =&gt; false,
      'class'         =&gt; array('form-row-wide'),
      'label'         =&gt; __('Whatever')
      ), $checkout-&gt;get_value( 'my_field' ));
  
  echo '&lt;/div&gt;';
  
  }
  
  /**
   * Update the order meta with field value
   */
  add_action( 'woocommerce_checkout_update_order_meta','my_custom_checkout_field_update_order_meta' );
  
  function my_custom_checkout_field_update_order_meta( $order_id ) {
  if ( ! empty( $_POST['my_field'] ) ) {
      update_post_meta( $order_id, 'My Field', sanitize_text_field( $_POST['my_field'] ) );
  }
  }
  }
  </code></pre>
  
  <p>Then, I tried to add them into the email order meta as shown at the 'Lesson 4' section in the tutorial:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>But, the custom fields do not appear in the email sent.</p>
  
  <p>I have also tried to test it by doing this in the email template file:</p>
  
  <pre><code>&lt;p&gt;&lt;?php echo $order-&gt;my_field; ?&gt;&lt;/p&gt;
  </code></pre>
  
  <p>Nothing is printed in the email.</p>
  
  <p>Solution please. Thanks in advance.</p>