Add a custom field in Woocommerce Edit Account page

Add a custom field in Woocommerce Edit Account page

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Add a custom field in Woocommerce Edit Account page

You’ve successfully hooked up a custom checkout field like favorite_color and users are happily entering their preferences during purchase. However, that data vanishes once they log into their dashboard to view their profile. The default "Edit Account" template renders standard user metadata (first name, last name, email), but it doesn't automatically include your custom meta keys.

Simply copying the HTML structure from myaccount/form-edit-account.php and swapping the field name often results in a UI that looks correct but fails to persist data on save. The form submits, but WooCommerce ignores the input because it doesn’t know how to handle the unknown key within its standard processing loop.

To make this work reliably, you need to intercept the form submission logic rather than just tweaking the frontend template. This requires modifying the woocommerce_before_save_account_details hook or using a filter on the meta data being saved.

The Template Approach and Its Limitations

Your initial attempt involved editing myaccount/form-edit-account.php. You replaced the standard input block:

<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
    <label for="account_first_name"><?php _e( 'First name', 'woocommerce' ); ?> <span class="required">*</span></label>
    <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="account_first_name" id="account_first_name" value="<?php echo esc_attr( $user->first_name ); ?>" />
</p>

With your custom field:

<p class="woocommerce-form-row woocommerce-form-row--first form-row form-row-first">
    <label for="favorite_color">Favorite Color</label>
    <input type="text" class="woocommerce-Input woocommerce-Input--text input-text" name="favorite_color" id="favorite_color" value="<?php echo esc_attr( $user->favorite_color ); ?>" />
</p>

While this successfully populates the field with existing data thanks to $user->favorite_color, it creates a disconnect during submission. The default save_account_details action in WooCommerce processes specific keys: account_first_name, account_last_name, account_email, and password fields. When the form posts, WooCommerce validates these known fields but discards anything outside that whitelist. Consequently, favorite_color is ignored by the core save routine.

The Robust Solution: Using Filters

To ensure your custom field saves correctly, you must explicitly tell WooCommerce to include it in the meta data update. The cleanest way to achieve this without overriding the entire form handler is by using the woocommerce_save_account_details filter or, more specifically for custom meta, the woocommerce_update_user_meta_args filter.

However, a more direct and reliable method for custom meta keys during the "Edit Account" flow is to ensure the value is passed to the user object before it is serialized. The most effective hook for this scenario is woocommerce_save_account_details. You can use this filter to append your custom field to the arguments being processed.

Add the following code to your theme's functions.php file or a custom plugin:

add_filter( 'woocommerce_save_account_details', function ( $user_id ) {
    if ( isset( $_POST['favorite_color'] ) ) {
        sanitize_text_field( $_POST['favorite_color'] ); // Prevent saving empty values if desired
        
        // Update the user meta. The key matches your checkout field name.
        update_user_meta( $user_id, 'favorite_color', sanitize_text_field( wp_unslash( $_POST['favorite_color'] ) ) );
    }

    return $user_id;
}, 10, 1 );

This snippet intercepts the post submission. It checks if the favorite_color key exists in the POST data (which your modified template provides). If it does, it sanitizes the input and updates the user meta table directly. This bypasses the need to modify WooCommerce's internal validation loops for standard fields.

Important Considerations

Security and Sanitization

When dealing with custom inputs, security is paramount. The default WooCommerce form uses wp_nonce_field to verify the request, but it does not validate arbitrary keys like favorite_color. Your code must perform sanitization (sanitize_text_field) before storing the value. Never rely solely on WordPress's automatic escaping for user-generated input stored in meta.

Theme Overrides

Overriding myaccount/form-edit-account.php is a valid practice if you want to control the layout or styling of your custom field (e.g., making it required, adding specific classes). However, remember that WooCommerce updates template files frequently. If you rely on copying lines directly from the core file, future updates might overwrite your changes or require version bumping logic. A safer approach for layout customization is often creating a child theme and overriding the template there, ensuring longevity of your design choices.

Integration with Checkout

Since you already have this field in the checkout flow, consistency is key. Ensure that the meta key used in the checkout (wc_add_to_cart or checkout_fields['billing']['favorite_color']) matches the key you are updating in the account profile. In WooCommerce, custom checkout fields usually store data under a prefixed key structure (often wc_ + prefix) unless explicitly configured otherwise. Verify that the meta key stored after checkout aligns with the key you are retrieving and updating on the "Edit Account" page to ensure data consistency across the user lifecycle.

By combining the frontend template override with the backend filter logic, you create a seamless experience where users can view and edit their preferences both at checkout and in their account profile, ensuring data integrity throughout the platform.

Our network