My Account Fields
Making Fields Not Required
For example I do not want the “Last name” to be required here, I can easily make it optional (or any other field) with the code below:
add_filter('woocommerce_save_account_details_required_fields', 'misha_myaccount_required_fields'); function misha_myaccount_required_fields( $account_fields ) { unset( $account_fields['account_last_name'] ); // unset( $account_fields['account_first_name'] ); // First name // unset( $account_fields['account_display_name'] ); // Display name return $required_fields; }
Have you inserted the code to your functions.php
? Done! The “Last name” field is not required any more.
Wait… But… The required field asterisk is still there! 🤔

I am not trying to fool you guys, try to remove the last name and hit the save button. It it saved? Absolutely.
And yes, I have bad news about the field asterisk… It is hardcoded!!! Okay, okay… Replacing form-edit-account.php
template just because of this asterisk definitely doesn’t seem like a good idea.
In this situation I think the best idea is to use CSS.
label[for="account_last_name"] .required { display: none; }
So far so good.

Remove Default Fields
What I am going to show you below doesn’t look like a clean solution, but it is the only one.
Step by step:
- Choose what fields you would like to remove and make them not required first (skip this step for the password fields).
- Duplicate this file
form-edit-account.php
from WooCommercetemplates/myaccount
to your current themewoocommerce/myaccount
directory, create it if not exists. - Remove the fields from that file code 😁
- Done!

Add a Custom Field (a required one)
Good news guys! If you want to add a custom field in WooCommerce my account page, there is no needs to hardcode anything in form-edit-account.php
file! There are two magnificent hooks for you:
woocommerce_edit_account_form_start
– if you want to add a field at the beginning.woocommerce_edit_account_form
– in case you want to add a field after the “Password change” section.
Let’s try it now! 🔥
You could display the field using the raw HTML here, but I think there is no reason to make everything so complicated while there is woocommerce_form_field() function which allows to make it so much easier!
/** * Step 1. Add your field */ add_action( 'woocommerce_edit_account_form', 'misha_add_field_edit_account_form' ); // or add_action( 'woocommerce_edit_account_form_start', 'misha_add_field_edit_account_form' ); function misha_add_field_edit_account_form() { woocommerce_form_field( 'country_to_visit', array( 'type' => 'text', 'required' => true, // remember, this doesn't make the field required, just adds an "*" 'label' => 'Country you want to visit the most', 'description' => 'Maybe it is Norway or New Zealand or...?', ), get_user_meta( get_current_user_id(), 'country_to_visit', true ) // get the data ); } /** * Step 2. Save field value */ add_action( 'woocommerce_save_account_details', 'misha_save_account_details' ); function misha_save_account_details( $user_id ) { update_user_meta( $user_id, 'country_to_visit', sanitize_text_field( $_POST['country_to_visit'] ) ); } /** * Step 3. Make it required */ add_filter('woocommerce_save_account_details_required_fields', 'misha_make_field_required'); function misha_make_field_required( $required_fields ){ $required_fields['country_to_visit'] = 'Country you want to visit the most'; return $required_fields; }
Here is my field:

It is worth mentioning that with the help of woocommerce_form_field() you can add fields of any type, like textarea, selects, radio buttons etc.
Comments — 11
Does this work for BBPress, too?
I didn’t test it with it.
Thanks
Thank you Misha
very useful Article
It Helped me a lot.
Mehdi Mousavi
You’re welcome!
Thanks for the article.Really appreciate your support.
Can you explain how we can place the field on “Account” interface.
E.g. My Custom Field is, “Title” and it’s currently showing bottom of the account form and i need to show it on top of the form. Thanks in advance
You’re welcome!
Please try
woocommerce_edit_account_form_start
action hook instead ofwoocommerce_edit_account_form
.Hi Misha,
It worked. Really appreciate your help
Awesome!
New custom fields don’t be shown in user area admin panel. How can i do for this function.
Thanks.
At this moment I don’t have a link or ready code for this.
Comments are closed.