Black Friday 2026: up to 50% off today See Deals Dismiss

Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Join
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets Custom fields Customer Registration My Account

WooCommerce: File Upload @ My Account Registration Form

Last Revised: Aug 2019

STAY UPDATED

You can add first and last name to the WooCommerce registration form (easy, no?). Or maybe a custom radio field. And why not, a file upload input – which is able to load an image from the user’s browser, assign it to the form, and add the image to “Media” in your WordPress install.

And today we’ll see exactly that. Unfortunately the “woocommerce_form_field” function does not allow (yet, maybe) to generate file input fields, so we’ll just use basic HTML. Enjoy!

Here’s a brand new file upload input on the WooCommerce My Account registration form

PHP Snippet: Add File Upload Field @ WooCommerce My Account Registration

/**
 * @snippet       File Upload @ WooCommerce My Account Registration
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 3.7
 * @community     https://businessbloomer.com/club/
 */

// --------------
// 1. Add file input to register form

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

// --------------
// 2. Validate new field

add_filter( 'woocommerce_registration_errors', 'bbloomer_validate_woo_account_registration_fields', 10, 3 );
 
function bbloomer_validate_woo_account_registration_fields( $errors, $username, $email ) {
    if ( isset( $_POST['image'] ) && empty( $_POST['image'] ) ) {
        $errors->add( 'image_error', __( 'Please provide a valid image', 'woocommerce' ) );
    }
    return $errors;
}

// --------------
// 3. Save new field

add_action( 'user_register', 'bbloomer_save_woo_account_registration_fields', 1 );
 
function bbloomer_save_woo_account_registration_fields( $customer_id ) {
	if ( isset( $_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 ) ) {
			update_user_meta( $customer_id, 'image', $_FILES['image'] . ": " . $attachment_id->get_error_message() );
		} else {
			update_user_meta( $customer_id, 'image', $attachment_id );
		}
	}
}

// --------------
// 4. Add enctype to form to allow image upload

add_action( 'woocommerce_register_form_tag', 'bbloomer_enctype_custom_registration_forms' );

function bbloomer_enctype_custom_registration_forms() {
	echo 'enctype="multipart/form-data"';
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: Add Custom Field to Product Variations
    Adding and displaying custom fields on WooCommerce products is quite simple. For example, you can add a “RRP/MSRP” field to a product, or maybe use…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back 🙂 In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

26 thoughts on “WooCommerce: File Upload @ My Account Registration Form”

  1. Dwaynne
    August 5, 2024

    Great stuff but why doesn’t the uploaded file show up in the WordPress dashboard?

    Reply
    1. Rodolfo Melogli
      August 13, 2024

      Like, you want to show it where exactly?

      Reply
  2. Jackson
    December 8, 2020

    How to add mobile number field in woocommerce registration form??

    Reply
    1. Rodolfo Melogli
      December 16, 2020

      Hi Jackson, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  3. Josh
    September 7, 2020

    Hi, this is working perfectly and saves me a lot of money not having to use a 3rd party plugin so thanks!!

    But what do I remove to have the field not required? I do want the user to add a photo in sign up but I also want them to be able to continue without adding a photo.

    Reply
    1. Rodolfo Melogli
      September 10, 2020

      Hi Josh, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  4. Rusal
    August 20, 2020

    Hi! I followed and copy your code snippets, however, I found out that the file uploaded can’t be traced as to who did upload it. I checked the media library to see if the uploaded file will go directly there and it was successfully added but in the author section nothing is stated there so the administrator won’t know who is the user/owner of the file uploaded. I would really appreciate if you can help me with it or at least understand why and give a little hint. Thank you so much! God bless you!

    Reply
    1. Rodolfo Melogli
      August 28, 2020

      Not 100% sure, sorry

      Reply
  5. Carlos David Mendez
    July 1, 2020

    Saludos Rodolfo, estoy interesado en contratar su servicio para que me ayude a solucionar una necesito que tengo en WooCommerce, espero pueda contactarme para explicarle la situación.

    Espero pueda ayudarme, muchas gracias!

    Reply
    1. Rodolfo Melogli
      July 7, 2020

      Hi Carlos, thanks so much for your comment! If you’d like to get a quote, feel free to contact me here

      Reply
  6. Shekhar
    June 25, 2020

    I want to send this uploaded attactment with email. How could I do that? For example, If I have a file upload field in woocommerce registration form and someone upload a file at the time of registration, then how could I send that uploaded file with email notification?

    Thanks!

    Reply
    1. Rodolfo Melogli
      June 28, 2020

      Shekhar, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  7. Munish Dhiman
    June 11, 2020

    How can i add this same field edit-account page please help me

    Reply
    1. Rodolfo Melogli
      June 15, 2020

      Hi Munish, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  8. JM
    May 25, 2020

    How about adding upload file to edit account page? Is it possible?

    Reply
    1. Rodolfo Melogli
      May 26, 2020

      Hi JM, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  9. Francisco Mosse
    May 10, 2020

    Hi!

    Very good tutorial. I am trying to make the same but for standard WordPress signup form. The code is OK, but how do I add enctype to normal signup form?

    Because this is for woocmmerce signup, no for normal WordPress signup.

    Thanks,
    Francisco

    Reply
    1. Rodolfo Melogli
      May 13, 2020

      Hi Francisco, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  10. Dan
    March 30, 2020

    Hi Rodolfo,
    Is it possible to have this upload button in the Downloads page on the Account area?
    Thanks,
    Dan

    Reply
    1. Rodolfo Melogli
      March 31, 2020

      Hey Dan, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
  11. ft
    December 2, 2019

    Hello Rodolfo! How are you?
    First of all, thank you so much for all tips!
    Is there any way to save the image not on media folder? I would like to show the attached image on the user profile?

    Reply
    1. Rodolfo Melogli
      December 2, 2019

      Hi, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
      1. ft
        December 3, 2019

        Thanks for answering me Rodolfo!
        Another question… when I upload the file, it doesn’t get any kind of ID to know that the file is from the user “X”.
        Is it too difficult?

        Reply
        1. Rodolfo Melogli
          December 6, 2019

          Not difficult, no, but will need some custom coding

          Reply
  12. Salma DJADI
    September 5, 2019

    Hello Rodolfo Melogli,
    Thank you very much for the help
    I’m beginner on woocommerce. i want to display this field on edit account page for the user, so he/she can modify it and also how i can display it on user profil for the admin so he/she can view or download and change the file ?
    thank you in advance

    Reply
    1. Rodolfo Melogli
      September 9, 2019

      Salma, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!

      Reply
Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Cancel reply

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


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: Simple Price Including/Excluding Tax Switcher
  • WooCommerce: Refund Request Button @ My Account
  • WooCommerce: Show or Hide Bank Accounts Based On Order
  • WooCommerce: Save Order Currency Exchange Rate
  • WooCommerce: Get Orders Containing a Specific Product

Latest Comments

  1. Rodolfo Melogli on WooCommerce: “Inconsistent tax settings” Error
  2. ARNo on WooCommerce: Attach Files (PDF, etc.) To Emails
  3. Rodolfo Melogli on WooCommerce: Only Allow 1 Product in the Cart

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x