title: Add image file upload field to WooCommerce single products
body: <p>i have created a custom plugin which dynamically displays custom fields in woocommerce single product page.
  Fields are displayed, added to cart and added to order data and emails.
  However i'm trying for days to add a file upload field with no luck.
  The field is displayed in the frontend like:</p>
  <pre><code>add_action( 'woocommerce_before_add_to_cart_button', 'display_custom_fields' );
  function display_custom_fields() {
  ?&gt;
      &lt;p class=&quot;form-row validate-required&quot; id=&quot;image&quot; &gt;
          &lt;span class=&quot;woocommerce-input-wrapper&quot;&gt;
          &lt;label for=&quot;image&quot; class=&quot;&quot;&gt;&lt;?php echo $stamp_welcome_text; ?&gt; &lt;/label&gt; 
          
          &lt;input type=&quot;file&quot; name=&quot;image&quot; accept=&quot;image/*&quot; &gt;
          &lt;/span&gt;
      &lt;/p&gt;
  &lt;?php
  }
  </code></pre>
  <p>and then added to cart like:</p>
  <pre><code>add_filter( 'woocommerce_add_cart_item_data', 'add_cart_item_data', 10,3 );
  function add_cart_item_data( $cart_item_data, $product_id ) {
      if ($_FILES['image'] ) {
          require_once( ABSPATH . 'wp-admin/includes/image.php' );
          require_once( ABSPATH . 'wp-admin/includes/file.php' );
          require_once( ABSPATH . 'wp-admin/includes/media.php' );
          $attachment_id = media_handle_upload( 'image', 0 );
          if ( is_wp_error( $attachment_id ) AND $_FILES['image']['size'] &gt; 0) {
              die($attachment_id-&gt;get_error_message().'. Παρακαλώ επικοινωνήστε μαζί μας.');
          } else $cart_item_data['image'] = $attachment_id;
      }
      return $item_cart_data;
  }
  </code></pre>
  <p>Of course this is only part of the code.The rest of the fields are working perfect. Yes, i have tried the code only by itself if anyone wonders.</p>
  <p>I have been &quot;playing&quot; around with it for days and i can't figure out what's wrong.
  Any help is highly appreciated :)</p>