WooCommerce Registration Custom Fields

WooCommerce

There are many reasons for using WooCommerce. Here are mine E-Commerce readiness, prevent user from accessing backend. The second one convinced me significantly. I know there are plugins doing same job. Please share your own reasons if you are using WooCommerce on your WordPress site or blog.

This is how WooCommerce My Account looks by default

WooCommerce Default

And what we want: couple of custom fields added into the form: First Name, Last Name, Phone, Company, Subscribe to our newsletter and terms & privacy policy

WooCommerce Signup Custom Fields

Here are couple of steps that I am going to cover:

  1. Create plugin folder structure
  2. Adding custom fields on frontend
  3. Validate these custom fields
  4. Save custom fields data to database
  5. Redirect all logins to WooCommerce “My Account”
  6. Notify user about registration status

Ready? Let’s get started

Create plugin folder structure

If you like, you can put all these snippets below to function.php of active theme. However I would strongly recommend you to put it to a WordPress Plugin so that you can reuse, share and maintain it with ease.

I name my plugin as “woocommerce-registration-custom-fields” so I create folder with same name and inside it. I also create couple of sub folders (follows WordPress Plugin best practice).

  • admin
  • includes
  • languages
  • public

In this article, I only use root folder (i.e. woocommerce-registration-custom-fields) and “includes”. In root folder, I create “woocommerce-registration-custom-fields.php” and it looks like this

Adding custom fields on front-end

Validate these custom fields

Save custom fields data to database

Redirect all logins to WooCommerce “My Account”

Wrapping up

Here’s what you accomplished in this tutorial:

  1. Create plugin folder structure
  2. Adding custom fields on frontend
  3. Validate these custom fields
  4. Save custom fields data to database
  5. Redirect all logins to WooCommerce “My Account”
  6. Notify user about registration status

If you need everything at once, you can download ready-to-use plugin on github. Leave a comment or feedback right below.


Leave a Reply