How to add custom fields to user registration form in Woocommerce?


In this tutorial we’ll learn how to add custom fields to user registration form in Woocommerce.

First of all enable the registration form backend Woocommerce settings.

After enabling this option you can see the registration form in the frontend.

As you can see it is a pretty modest form, but we can add more fields to this form by using following actions.

  • woocommerce_register_form_start- Appears before the “Address Email” field
  • woocommerce_register_form- Appears after the “Password” field

Now to add additional fields like first name, last name and phone number etc. add the following lines of code at the end of your theme’s functions.php file.


* Add new register fields for WooCommerce registration.


* @return string Register fields HTML.


functionwooc_extra_register_fields() {



       <p class="form-row form-row-first">

       <label for="reg_billing_first_name"><?php _e( 'First name', 'woocommerce' ); ?><span class="required">*</span></label>

       <input type="text" class="input-text" name="billing_first_name" id="reg_billing_first_name" value="<?php if ( ! empty( $_POST['billing_first_name'] ) ) esc_attr_e( $_POST['billing_first_name'] ); ?>" />



       <p class="form-row form-row-last">

       <label for="reg_billing_last_name"><?php _e( 'Last name', 'woocommerce' ); ?><span class="required">*</span></label>

       <input type="text" class="input-text" name="billing_last_name" id="reg_billing_last_name" value="<?php if ( ! empty( $_POST['billing_last_name'] ) ) esc_attr_e( $_POST['billing_last_name'] ); ?>" />



       <div class="clear"></div>


       <p class="form-row form-row-wide">

       <label for="reg_billing_phone"><?php _e( 'Phone', 'woocommerce' ); ?><span class="required">*</span></label>

       <input type="text" class="input-text" name="billing_phone" id="reg_billing_phone" value="<?php if ( ! empty( $_POST['billing_phone'] ) ) esc_attr_e( $_POST['billing_phone'] ); ?>" />






add_action( 'woocommerce_register_form_start', 'wooc_extra_register_fields' );

You can access functions.php file here:

Now if you refresh the page you’ll see the fields being added to registration form.

To associate these registration form fields with the billing address you need to add the prefix “billing_” before the field name. Following is the list of all the valid form fields that can be added to registration form and can be associated with billing address.

  • billing_first_name
  • billing_last_name
  • billing_company
  • billing_address_1
  • billing_address_2
  • billing_city
  • billing_postcode
  • billing_country
  • billing_state
  • billing_email
  • billing_phone

Now we also need to validate these newly added form fields. To validate these form fields add, the following lines of code at the end of your functions.php file.


* Validate the extra register fields.


* @param string $username         Current username.

* @param string $email             Current email.

* @param object $validation_errorsWP_Error object.


* @return void


functionwooc_validate_extra_register_fields( $username, $email, $validation_errors ) {

       if ( isset( $_POST['billing_first_name'] ) && empty( $_POST['billing_first_name'] ) ) {

              $validation_errors->add( 'billing_first_name_error', __( '<strong>Error</strong>: First name is required!', 'woocommerce' ) );



       if ( isset( $_POST['billing_last_name'] ) && empty( $_POST['billing_last_name'] ) ) {

              $validation_errors->add( 'billing_last_name_error', __( '<strong>Error</strong>: Last name is required!.', 'woocommerce' ) );




       if ( isset( $_POST['billing_phone'] ) && empty( $_POST['billing_phone'] ) ) {

              $validation_errors->add( 'billing_phone_error', __( '<strong>Error</strong>: Phone is required!.', 'woocommerce' ) );




add_action( 'woocommerce_register_post', 'wooc_validate_extra_register_fields', 10, 3 );

If you like into the code of this function you’ll figure out that it is just checking $_POST array for form values and adding an error message if value is not present or in valid data.

In this way you can also add multiple validation rules and can also add validation rules to other fields as well. You can see one of our custom validation rule being applied:

Finally, we need to save these values to database.

To insert values in database add the following function in your theme’s functions.php file:


* Save the extra register fields.


* @paramint $customer_id Current customer ID.


* @return void


functionwooc_save_extra_register_fields( $customer_id ) {

       if ( isset( $_POST['billing_first_name'] ) ) {

              // WordPress default first name field.

              update_user_meta( $customer_id, 'first_name', sanitize_text_field( $_POST['billing_first_name'] ) );


              // WooCommerce billing first name.

              update_user_meta( $customer_id, 'billing_first_name', sanitize_text_field( $_POST['billing_first_name'] ) );



       if ( isset( $_POST['billing_last_name'] ) ) {

              // WordPress default last name field.

              update_user_meta( $customer_id, 'last_name', sanitize_text_field( $_POST['billing_last_name'] ) );


              // WooCommerce billing last name.

              update_user_meta( $customer_id, 'billing_last_name', sanitize_text_field( $_POST['billing_last_name'] ) );



       if ( isset( $_POST['billing_phone'] ) ) {

              // WooCommerce billing phone

              update_user_meta( $customer_id, 'billing_phone', sanitize_text_field( $_POST['billing_phone'] ) );




add_action( 'woocommerce_created_customer', 'wooc_save_extra_register_fields' );

And we are done here, now the newly added fields has been added, validated and inserted for future use.

On the billing address page in your account, you need to click on edit to go there, You can see the values from registration form already being populated.

Editorial Staff

ThemeLocation Provides Wordpress & Woocommerce development & Customization services. Have a Project? Contact To discuss

One thought on “How to add custom fields to user registration form in Woocommerce?

  1. How about adding custom fields like a dropdown select for Account Types or fields that are not associated with the Billing Address? E.g.

    Account Type: (as a dropdown field)
    Account 1
    Account 2
    Account 3
    Account 4

    Would appreciate some ideas. I have searched for this purpose but haven’t found any. Thank you.

Leave a Reply

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