title: Dynamically added custom fields not displayed on WooCommerce email notifications
body: <p>I have a different kind of scenario then the typical custom fields (I suppose). I am not getting custom values (fields) from user in the form rather I have an implementation which adds:</p>
  <ul>
  <li>ColorName</li>
  <li>Size</li>
  <li>City</li>
  </ul>
  <p>These are from a custom product flow which adds custom attributes to the cart, here is how I am doing that:</p>
  <pre><code>add_action('wp_ajax_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
  add_action('wp_ajax_nopriv_wdm_add_user_custom_data_options', 'wdm_add_user_custom_data_options_callback');
  
  
  function wdm_add_user_custom_data_options_callback()
  {
      // print_r($_POST);
      $productIDM = $_POST['product_id'];
      // case swith
      switch ($productIDM) {
          case &quot;Ace Dura Silk&quot;:
              $productID = 3254;
              break;
          case &quot;Ace Matt Finish&quot;:
              $productID = 3232;
              break;
          case &quot;Ace Plastic Emulsion&quot;:
              $productID = 3276;
              break;
          case &quot;Ace Weather Defender&quot;:
              $productID = 2991;
              break;
          case &quot;Overall Plasticoat&quot;:
              $productID = 3112;
              break;
        }
  
      $colorname = $_POST['colorname'];
      $cityname = $_POST['cityname'];
      $size = $_POST['size'];
      $price = $_POST['price'];
      global $woocommerce;
      $woocommerce-&gt;cart-&gt;add_to_cart( $productID, 1 );
      //   die();
      // echo 'I am in...';
      $result = array(
          'status' =&gt; true
      );
      echo json_encode($result);
  }
  add_filter('woocommerce_add_cart_item_data','wdm_add_item_data',1,10);
  function wdm_add_item_data($cart_item_data, $product_id) {
  
      global $woocommerce;
      $new_value = array();
      $new_value['_custom_options'] = $_POST['custom_options'];
  
      if(empty($cart_item_data)) {
          return $new_value;
      } else {
          return array_merge($cart_item_data, $new_value);
      }
  }
  
  add_filter('woocommerce_get_cart_item_from_session', 'wdm_get_cart_items_from_session', 1, 3 );
  function wdm_get_cart_items_from_session($item,$values,$key) {
  
      if (array_key_exists( '_custom_options', $values ) ) {
          $item['_custom_options'] = $values['_custom_options'];
      }
  
      return $item;
  }
  add_filter('woocommerce_cart_item_name','add_usr_custom_session',1,3);
  function add_usr_custom_session($product_name, $values, $cart_item_key ) {
  
      $return_string = $product_name . &quot;&lt;div class='cart_subitems_custom'&gt;&lt;br /&gt;&lt;small&gt;&quot;.$values['_custom_options']['colorname'].&quot;&lt;/small&gt;&lt;br /&gt;&lt;small&gt;&quot;.$values['_custom_options']['cityname'].&quot;&lt;/small&gt;&lt;br /&gt;&lt;small&gt;&quot;.$values['_custom_options']['size'].&quot;&lt;/small&gt;&lt;/div&gt;&quot; ; //. &quot;&lt;br /&gt;&quot; . print_r($values['_custom_options']);
      return $return_string;
  
  }
  add_action('woocommerce_add_order_item_meta','wdm_add_values_to_order_item_meta',1,2);
  function wdm_add_values_to_order_item_meta($item_id, $values) {
      global $woocommerce,$wpdb;
  
      wc_add_order_item_meta($item_id,'_colorname',$values['_custom_options']['colorname']);
      wc_add_order_item_meta($item_id,'_cityname',$values['_custom_options']['cityname']);
      wc_add_order_item_meta($item_id,'_size',$values['_custom_options']['size']);
  
  }
  add_action( 'woocommerce_before_calculate_totals', 'update_custom_price', 1, 1 );
  function update_custom_price( $cart_object ) {
      foreach ( $cart_object-&gt;cart_contents as $cart_item_key =&gt; $value ) {       
          // Version 2.x
          //$value['data']-&gt;price = $value['_custom_options']['custom_price'];
          // Version 3.x / 4.x
           if($value['_custom_options']['price'] == null){
              echo&quot;&quot;;
          }else{
              $value['data']-&gt;set_price($value['_custom_options']['price']);
          }
      }
  }
  </code></pre>
  <p><strong>I am getting these custom values almost everywhere except Email Notification.</strong></p>
  <p>Here is what normal product order edit shows:</p>
  <p><a href="https://i.stack.imgur.com/sd8RF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sd8RF.png" alt="enter image description here" /></a></p>
  <p>Here is how I am getting the custom product in order edit page:</p>
  <p><a href="https://i.stack.imgur.com/08kmd.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/08kmd.png" alt="enter image description here" /></a></p>
  <p>I have tried all the solution I can possibly find (filter &amp; action hooks) but nothing works for me.</p>
  <p>I have tried <a href="https://stackoverflow.com/questions/49428107/display-custom-meta-field-value-on-woocommerce-email-notifications">first answer from this</a>:</p>
  <pre><code>add_action( 'woocommerce_checkout_create_order_line_item', 'custom_checkout_create_order_line_item', 20, 4 );
  function custom_checkout_create_order_line_item( $item, $cart_item_key, $values, $order ) {
      if( isset( $values['colorname'] ) )
          $item-&gt;add_meta_data( __('DCM Shade'), $values['_colorname'] );
  }
  </code></pre>
  <p>Also the common method I found everywhere:</p>
  <pre><code>function custom_woocommerce_email_order_meta_fields( $fields, $sent_to_admin, $order ) {
      // Get meta
      $color = $order-&gt;get_meta( 'colorname', true );
      
      // NOT empty
      if( ! empty( $color ) ) {  
          $fields['colorname'] = array(
              'label' =&gt; __( 'Shade' ),
              'value' =&gt; $color,
          );
      }
      
      // Get (other) meta
      $shipping_email = $order-&gt;get_meta( '_cityname', true );
      
      // NOT empty
      if ( ! empty( $shipping_email ) ) { 
          $fields['_cityname'] = array(
              'label' =&gt; __( 'City' ),
              'value' =&gt; $shipping_email,
          );
      }
      
      return $fields;
  }
  add_filter( 'woocommerce_email_order_meta_fields', 'custom_woocommerce_email_order_meta_fields', 10, 3 );
  </code></pre>
  <p>But I can't get the custom fields.</p>
  <p>What am I doing wrong can please anyone please guide me.</p>