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
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
Here are couple of steps that I am going to cover:
- Create plugin folder structure
- Adding custom fields on frontend
- Validate these custom fields
- Save custom fields data to database
- Redirect all logins to WooCommerce “My Account”
- 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:
- Create plugin folder structure
- Adding custom fields on frontend
- Validate these custom fields
- Save custom fields data to database
- Redirect all logins to WooCommerce “My Account”
- 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.