title: Add custom field data to WooCommerce order
body: <p>I have a custom field on my WooCommerce single product. It sends to the cart fine, it displays on checkout fine, it shows in the order in the dashboard fine.</p>
  
  <p>What I am now trying to do is set the value as a custom field in the order page so I am able to amend the text when I need to. For some reason when I submit the form this step isn't working.</p>
  
  <p>The code that i use in my <code>functions.php</code>file:</p>
  
  <pre><code>// Add the field to the product
  add_action('woocommerce_before_add_to_cart_button', 'my_custom_checkout_field');
  
  function my_custom_checkout_field() {
      echo '&lt;div id="my_custom_checkout_field"&gt;&lt;h3&gt;'.__('My Field').'&lt;/h3&gt;';
      echo  '&lt;label&gt;fill in this field&lt;/label&gt; &lt;input type="text" name="my_field_name"&gt;';
      echo '&lt;/div&gt;';
  }
  
  // Store custom field
  function save_my_custom_checkout_field( $cart_item_data, $product_id ) {
      if( isset( $_REQUEST['my_field_name'] ) ) {
          $cart_item_data[ 'my_field_name' ] = $_REQUEST['my_field_name'];
          /* below statement make sure every add to cart action as unique line item */
          $cart_item_data['unique_key'] = md5( microtime().rand() );
      }
      return $cart_item_data;
  }
  add_action( 'woocommerce_add_cart_item_data', 'save_my_custom_checkout_field', 10, 2 );
  
  // Render meta on cart and checkout
  function render_meta_on_cart_and_checkout( $cart_data, $cart_item = null ) {
      $custom_items = array();
      /* Woo 2.4.2 updates */
      if( !empty( $cart_data ) ) {
          $custom_items = $cart_data;
      }
      if( isset( $cart_item['my_field_name'] ) ) {
          $custom_items[] = array( "name" =&gt; 'My Field', "value" =&gt; $cart_item['my_field_name'] );
      }
      return $custom_items;
  }
  add_filter( 'woocommerce_get_item_data', 'render_meta_on_cart_and_checkout', 10, 2 );
  
  // Display as order meta
  function my_field_order_meta_handler( $item_id, $values, $cart_item_key ) {
      if( isset( $values['my_field_name'] ) ) {
          wc_add_order_item_meta( $item_id, "my_field_name", $values['my_field_name'] );
      }
  }
  add_action( 'woocommerce_add_order_item_meta', 'my_field_order_meta_handler', 1, 3 );
  
  /** THIS IS WHERE I'M STUCK **/
  
  add_action('woocommerce_checkout_process', 'my_custom_checkout_field_process');
  function my_custom_checkout_field_process() {
      global $woocommerce;
  
      // Check if set, if its not set add an error. This one is only requite for companies
      if ($_POST['billing_company'])
          if (!$_POST['my_field_name']) 
              $woocommerce-&gt;add_error( __('Please enter your XXX.') );
  }
  // Update the user meta with field value
  add_action('woocommerce_checkout_update_user_meta', 'my_custom_checkout_field_update_user_meta');
  function my_custom_checkout_field_update_user_meta( $user_id ) {
      if ($user_id &amp;&amp; $_POST['my_field_name']) update_user_meta( $user_id, 'my_field_name', esc_attr($_POST['my_field_name']) );
  }
  
  // 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 ($_POST['my_field_name']) update_post_meta( $order_id, 'My Field', esc_attr($_POST['my_field_name']));
  }
  </code></pre>
  
  <p>Screenshot of what currently happens:</p>
  
  <p><a href="https://i.stack.imgur.com/CExKU.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CExKU.png" alt="Screenshot of what currently happens"></a></p>
  
  <hr>
  
  <hr>
  
  <p>What I would like to happen: </p>
  
  <p><a href="https://i.stack.imgur.com/5TVft.png" rel="noreferrer"><img src="https://i.stack.imgur.com/5TVft.png" alt="what I would like to happen"></a></p>
  
  <hr>
  
  <p>Any help would be greatly appreciated.</p>