WooCommerce : Upload File in My Account Registration Form.

Code

How to upload profile picture or any file during WooCommerce My Account Registration?

For uploading file from WooCommerce My Account Registration form we need to set form enctype type To multipart/form-data.secondly , we need to add html tags for input type file to upload file. then we need to validate them if the field field is required.Finally after upload file enter media id to user meta.

For uploading files may be image or other files in WooCommerce Registration form. We should follow these steps

  1. Make form enctype type To multipart/form-data
  2. We have to add html of input type file in form
  3. Than we have to validate these fields
  4. Than Finally Upload File and save field to User meta

Step 1 : We have to use ‘woocommerce_register_form_tag’ Hook.

// Add enctype to form to allow file upload
function AddEnctypeCustomRegistrationForms() {
  echo 'enctype="multipart/form-data"';
}
add_action('woocommerce_register_form_tag','AddEnctypeCustomRegistrationForms');

Step 2 : We have to use ‘woocommerce_register_form’ Hook.

// Add file input html to register form
add_action('woocommerce_register_form','AddImageField');
function AddImageField() {   
  ?>    
    <p class="form-row validate-required" id="pro_image" data-priority="">
    <label for="pro_image" class="">Image (JPG, PNG, PDF)<abbr class="required" title="required">*</abbr></label>
    <span class="woocommerce-input-wrapper">
      <input type='file' name='pro_image' accept='image/*,.pdf' required>
    </span>
    </p> 
  <?php       
}

Step 3: We have to use ‘woocommerce_registration_errors’ Hook.

// Validate new fields
function ValidateImageField( $errors, $username, $email ) {
  if ( isset( $_POST['pro_image'] ) && empty( $_POST['pro_image'] ) ) {
    $errors->add('pro_image_error', __( 'Please provide a valid image', 'woocommerce' ) );
  }
  return $errors;
}
add_filter('woocommerce_registration_errors','ValidateImageField',10,3 );

Step 4: We have to use ‘user_register’ Hook.

// Save new field
function SaveImageField( $customer_id ) {
  if ( isset( $_FILES['pro_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' );
    $attach_id= media_handle_upload('pro_image', 0 );
    if ( is_wp_error( $attach_id) ) {
      update_user_meta( $customer_id,'pro_image', $_FILES['pro_image'] . ": " . $attach_id->get_error_message() );
    } else {
      update_user_meta( $customer_id,'pro_image', $attach_id);
    }
  }
}
add_action('user_register','SaveImageField',1);
null

Related reading:

Shiv Kumawat

Executive Director & CEO

Shiv Kumawat is the CEO of Eoxys IT Solution LLP, a Jaipur-based IT and GenAI development company he has led since 2009. Eoxys has delivered 700+ projects, building custom AI agents, chatbots, mobile apps and web platforms for businesses worldwide. Shiv writes about practical AI app development and what it takes to ship software that works.

Latest Posts

Illustration of how to build a ChatGPT plugin for your business: a chat window with a business app docked in a sidebar panel, connected to a storefront, servers and a database

Build a ChatGPT Plugin for Your Business: What DevDay Changed

At DevDay on 29 September 2026, OpenAI opened up the platform it uses to build ChatGPT’s own features. Plugins can…

Shiv Kumawat
October 12, 2026
Isometric illustration of a business hiring a remote AI development team in India, with a laptop showing an AI chip linked across a globe to developer workstations

Hire AI Developers in India: Models, Vetting and Red Flags

If you plan to hire AI developers in India, the hard part is not finding people. It is telling a…

Shiv Kumawat
October 11, 2026
DPDP compliance for AI apps: isometric shield protecting a phone and cloud server, with consent toggle, padlock and data cubes on a navy background

DPDP Compliance for AI Apps: What to Fix Before May 2027

If your app or AI chatbot handles personal data of people in India, DPDP compliance for AI apps is now…

Shiv Kumawat
October 10, 2026
,

Leave a Reply

Your email address will not be published. Required fields are marked *