fbpx

How to add the additional fields on the account creation form — WooCommerce?

How to add the additional fields on the account creation form — WooCommerce?

To allow customers to create an account, you may need to add additional fields on the WordPress form.  By default, WooCommerce offers the option to activate the “Email address” and “password” fields. However, these fields are frequently not representative of business realities. So, we will see how to add the fields that interest us. This is without having to install an extension.

Follow the steps below to add an extra field to WooCommerce registration form

To add an extra field to the WooCommerce registration form, you can follow these steps:

  • Open your WordPress dashboard and navigate to the “Appearance” section.
  • Select “Theme Editor” from the drop-down menu.
  • In the list of theme files on the right side of the screen, select “functions.php”.
  • Scroll to the bottom of the “functions.php” file and add the following code:

<?php 
// Add new field to registration form
add_action( 'woocommerce_register_form', 'add_extra_registration_field' );
function add_extra_registration_field() {
?>
    <p class="form-row form-row-wide">
        <label for="extra_field"><?php _e( 'Extra Field', 'woocommerce' ); ?> <span class="required">*</span></label>
        <input type="text" class="input-text" name="extra_field" id="extra_field" value="<?php if ( ! empty( $_POST['extra_field'] ) ) esc_attr_e( $_POST['extra_field'] ); ?>" />
    </p>
<?php
}

// Validate the new field
add_action( 'woocommerce_register_post', 'validate_extra_registration_field', 10, 3 );
function validate_extra_registration_field( $username, $email, $validation_errors ) {
    if ( isset( $_POST['extra_field'] ) && empty( $_POST['extra_field'] ) ) {
        $validation_errors->add( 'extra_field_error', __( 'Please provide a value for the extra field', 'woocommerce' ) );
    }
}

// Save the new field
add_action( 'woocommerce_created_customer', 'save_extra_registration_field' );
function save_extra_registration_field( $customer_id ) {
    if ( isset( $_POST['extra_field'] ) ) {
        update_user_meta( $customer_id, 'extra_field', sanitize_text_field( $_POST['extra_field'] ) );
    }
}

  • Save the changes in the “functions.php” file.

This code will add a new field called “Additional Field” to the WooCommerce registration form. It will also validate the field to ensure it is not left blank and save the field value to the user’s metadata upon signup. You can customize the field label and validation message by modifying the text in the add_extra_registration_field() and validate_extra_registration_field() functions, respectively.

Use a WordPress plugin

If you are not familiar with PHP programming, you can use an extension to perform the same task. For this, below are some extensions we recommend.

However, it should be noted that these extensions may have a price.

1-Custom User Registration Fields for WooCommerce; ($49 / year)

It is a WooCommerce extension that you will find on the WooCommerce.com website. In order to use the extension, you need to place the order and follow the steps on the website.

2 – Custom Fields for WooCommerce; ($79 / year)

It is similarly an extension that you will find on WooCommerce. Click the link to download.

Other extensions that might be free

However, there are several other WordPress extensions to add additional fields on the WooCommerce account creation form. So, you can always find one that suits you. For this case, here are some of the most popular options:

  1. Ultimate Member:  It is a powerful member management plugin that allows you to add custom fields to the WooCommerce account creation page. It also provides a user-friendly and easy-to-use interface to customize the account creation form.
  2. WooCommerce Checkout Manager:  This plugin allows you to customize the Command fields of WooCommerce and add additional fields to the account creation page. It also provides a drag-and-drop interface to customize fields.
  3. Profile Builder:  This WooCommerce profile management plugin helps you customize the account creation page by adding additional fields. In addition, it does not require programming knowledge.
  4. Advanced Custom Fields:  Although it is not specifically designed for WooCommerce, this popular plugin allows you to add custom fields to any page of your WordPress site, including the WooCommerce account creation page. Like the others, it offers an intuitive user interface and many customization options.

All these plugins are available in the official directory of WordPress plugins. However, it is important to note that some extensions may require a premium version to access some advanced features. Therefore, be sure to check the features offered by each plugin before choosing the one that best suits your needs.

Conclusion

There are various approaches to adding additional fields on the account creation page. If you require help with custom development, contact us. Extensions or plugins are not always adapted to your needs or require additional fees. In this case, opt for custom developments, you will save over the long term.

Gilblas Ngunte Possi

Gilblas Ngunte Possi

Founder and Full-Stack Developer at Prositeweb.

My proficiency with modern tools and a keen analytical sense regarding information technology enable me to provide superior guidance in the development and implementation of your web solutions.

Gilblas Ngunte Possi

Gilblas
Typically replies within an hour

Gilblas
Hi there👋

How can I help you?
1:40
Chat with Us