title: Save Woocommerce cart item custom data as order item meta data displaying it on orders and emails
body: <p>Regarding Woocommerce. I have custom data that I am adding to the cart. In the functions.php file, I have the following function.</p>
  <pre><code>// Display cart item custom data in cart and checkout pages
  add_filter( 'woocommerce_get_item_data', 'display_cart_item_custom_on_cart_and_checkout', 10, 2 );
  function display_cart_item_custom_on_cart_and_checkout( $cart_item_data, $cart_item ){
      
      if( isset($cart_item['custom_data']['label0']) &amp;&amp; isset($cart_item['custom_data']['value0']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label0'],
              'value' =&gt; $cart_item['custom_data']['value0'],
          );
      }
      
      if( isset($cart_item['custom_data']['label']) &amp;&amp; isset($cart_item['custom_data']['value']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label'],
              'value' =&gt; $cart_item['custom_data']['value'],
          );
      }
  
      if( isset($cart_item['custom_data']['label2']) &amp;&amp; isset($cart_item['custom_data']['value2']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label2'],
              'value' =&gt; $cart_item['custom_data']['value2'],
          );
      }
      
      if( isset($cart_item['custom_data']['label3']) &amp;&amp; isset($cart_item['custom_data']['value3']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label3'],
              'value' =&gt; $cart_item['custom_data']['value3'],
          );
      }
      
      if( isset($cart_item['custom_data']['label4']) &amp;&amp; isset($cart_item['custom_data']['value4']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label4'],
              'value' =&gt; $cart_item['custom_data']['value4'],
          );
      }
      
      if( isset($cart_item['custom_data']['label5']) &amp;&amp; isset($cart_item['custom_data']['value5']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label5'],
              'value' =&gt; $cart_item['custom_data']['value5'],
          );
      }
      
      if( isset($cart_item['custom_data']['label6']) &amp;&amp; isset($cart_item['custom_data']['value6']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label6'],
              'value' =&gt; $cart_item['custom_data']['value6'],
          );
      }
      
      if( isset($cart_item['custom_data']['label7']) &amp;&amp; isset($cart_item['custom_data']['value7']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label7'],
              'value' =&gt; $cart_item['custom_data']['value7'],
          );
      }
      
      if( isset($cart_item['custom_data']['label8']) &amp;&amp; isset($cart_item['custom_data']['value8']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label8'],
              'value' =&gt; $cart_item['custom_data']['value8'],
          );
      }
      
      if( isset($cart_item['custom_data']['label9']) &amp;&amp; isset($cart_item['custom_data']['value9']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label9'],
              'value' =&gt; $cart_item['custom_data']['value9'],
          );
      }
      
      if( isset($cart_item['custom_data']['label10']) &amp;&amp; isset($cart_item['custom_data']['value10']) ) {
          $cart_item_data[] = array(
              'name' =&gt; $cart_item['custom_data']['label10'],
              'value' =&gt; $cart_item['custom_data']['value10'],
          );
      }
      return $cart_item_data;
  }
  </code></pre>
  <p>This works and the custom data is shown in the cart. However, the custom data does not show on the order and order email. I have seen, on Stackoverflow several answers that provide solutions to this problem but I cannot make them work for my situation. The solutions that I reference are.</p>
  <p><a href="https://stackoverflow.com/questions/53687705/save-and-display-order-item-custom-meta-data-in-woocommerce">Save and display order item custom meta data in Woocommerce</a></p>
  <p><a href="https://stackoverflow.com/questions/54505642/display-and-save-added-custom-cart-item-data-on-woocommerce-cart-checkout-and-o">Display and save added custom cart item data on Woocommerce Cart, Checkout and Orders</a></p>
  <p>Can anybody kindly show me what &quot;my&quot; function should be?</p>
  <p>Thank you.</p>