Reserve Your Free Seat for Our Next WooCommerce Class! Search
Business Bloomer
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • 0
  • Business Bloomer Club
  • WooCommerce Plugins
  • WooCommerce Tips
  • Log In
  • Search
  • Contact
  • Cart
WooCommerce Code Snippets Customer My Account

WooCommerce: Edit User Field @ My Account

Last Revised: Feb 2024

STAY UPDATED

Each WordPress user comes with a set of pre-defined fields. These fields store essential information about each user, including the username, name, email, role, website URL, bio, etc.

User fields can be edited in two ways: by the admin, who has access to all user profiles and can edit any user data, including both default and custom fields; and by logged-in users, who can edit their own profile information.

WooCommerce users (customers) can also edit some user data from the My Account page: name, email and password (Account details tab); and also billing and shipping addresses (Addresses tab).

But what if we want to let customers set/edit their bio or their website URL, which are only editable from the WordPress edit profile page? Well, the snippet below will help you display and save data for a default user field, under the Account details tab of the My Account page. Enjoy!

Here’s a quick way to display any of the default user field inputs under My Account > Account details WooCommerce page

PHP Snippet: Display User Field Input @ WooCommerce My Account > Account Details

This code snippet adds a user bio field to the WooCommerce edit account form and saves the updated bio to the user’s profile.

The woocommerce_edit_account_form action hooks the function bbloomer_edit_user_bio_my_account to the WooCommerce edit account form. This means the function will be called when the edit account form is displayed.

The bbloomer_edit_user_bio_my_account function retrieves the current user information and creates the HTML structure for the user bio field within the edit account form. It includes a label, a textarea for entering the bio, and a “clear” element for proper layout.

The woocommerce_save_account_details action hooks the function bbloomer_save_user_bio_my_account to the WooCommerce save account details action. This means the function will be called when the user clicks on the “Save changes” button.

bbloomer_save_user_bio_my_account retrieves the submitted value from the “account_bio” field, sanitizes it, and updates the user’s description field if the bio is not empty.

/**
 * @snippet       Edit User Field @ Woo My Account
 * @tutorial      https://businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @compatible    WooCommerce 8
 * @community     Join https://businessbloomer.com/club/
 */

add_action( 'woocommerce_edit_account_form', 'bbloomer_edit_user_bio_my_account' );

function bbloomer_edit_user_bio_my_account() {
	$user = get_user_by( 'id', get_current_user_id() );
	?>
	<p class="woocommerce-form-row woocommerce-form-row--wide form-row form-row-wide">
		<label for="account_bio"><?php esc_html_e( 'Biographical Info', 'wordpress' ); ?>&nbsp;<span class="required">*</span></label>
		<textarea class="woocommerce-Input woocommerce-Input--text input-text" name="account_bio" id="account_bio"><?php echo esc_attr( $user->description ); ?></textarea>
	</p>
	<div class="clear"></div>
	<?php
}

add_action( 'woocommerce_save_account_details', 'bbloomer_save_user_bio_my_account' );
	
function bbloomer_save_user_bio_my_account( $user_id ) {
	$account_bio = ! empty( $_POST['account_bio'] ) ? wc_clean( wp_unslash( $_POST['account_bio'] ) ) : '';
	if ( $account_bio ) {
		$user = new stdClass();
		$user->description = $account_bio;
		wp_update_user( $user );
	}
}

Where to add custom code?

You should place custom PHP in functions.php and custom CSS in style.css of your child theme: where to place WooCommerce customization?

This code still works, unless you report otherwise. To exclude conflicts, temporarily switch to the Storefront theme, disable all plugins except WooCommerce, and test the snippet again: WooCommerce troubleshooting 101

Related content

  • WooCommerce: Separate Login, Registration, My Account Pages
    There are times when you need to send logged out customers to a Login page and unregistered customers to a standalone Register page. As you…
  • WooCommerce: Add New Tab @ My Account Page
    One of the features of Business Bloomer Club is the provision of Premium WooCommerce Q&A Support to supporters who enroll. So, how to add an…
  • WooCommerce: How To Make A Website GDPR Compliant? (12 Steps)
    Ok, we all know that the EU General Data Protection Regulation (GDPR) will come into force on the 25th May 2018. So the main question…
  • WooCommerce Visual Hook Guide: My Account Pages
    Hey WooCustomizers, the Visual Hook Guide is back 🙂 In this episode, I’ve created a visual HTML hook guide for the WooCommerce Account Pages (there…
  • WooCommerce: Add First & Last Name to My Account Register Form
    Here’s yet another useful PHP snippet – and a mini-plugin alternative with super simple settings – that adds the Billing First Name and Billing Last…

Rodolfo Melogli

Business Bloomer Founder

Author, WooCommerce expert and WordCamp speaker, Rodolfo has worked as an independent WooCommerce freelancer since 2011. His goal is to help entrepreneurs and developers overcome their WooCommerce nightmares. Rodolfo loves travelling, chasing tennis & soccer balls and, of course, wood fired oven pizza. Follow @rmelogli

Questions? Feedback? Customization? Leave your comment now!
_____

If you are writing code, please wrap it like so: [php]code_here[/php]. Failure to complying with this, as well as going off topic or not using the English language will result in comment disapproval. You should expect a reply in about 2 weeks - this is a popular blog but I need to get paid work done first. Please consider joining the Business Bloomer Club to get quick WooCommerce support. Thank you!

Cancel reply

Your email address will not be published. Required fields are marked *


Search WooCommerce Tips

Popular Searches: Visual Hook Guides - Checkout Page - Cart Page - Single Product Page - Add to Cart - Emails - Shipping - Prices - Hosting

Recent Articles

  • WooCommerce: How to Configure Product and Order Sync
  • WooCommerce: “Beautify” Item Meta in Order Emails
  • WooCommerce: Per-Product Checkout Fees / Tariffs
  • WooCommerce: Auto-Cancel Orders After 3 Failed Payments
  • WooCommerce: Bulk Delete Pending / Failed Scheduled Actions

Latest Comments

  1. Piotr on WooCommerce: Replace Variable Price With Active Variation Price
  2. Rodolfo Melogli on WooCommerce: Redirect Empty Paginated Category Pages (404)
  3. Rodolfo Melogli on WooCommerce: Allow to “Pay for Order” Without Login

Find Out More

  • Become a WooCommerce Expert
  • Business Bloomer Club
  • WooCommerce Blog
  • WooCommerce Weekly
  • Contact

Contact Info

Ciao! I'm Rodolfo Melogli, an Italian Civil Engineer who has turned into an international WooCommerce expert. You can contact me here:

Twitter: @rmelogli

Get in touch: Contact Page

Business Bloomer © 2011-2025 - VAT IT02722220817 - Terms of Use - Privacy Policy

Cart reminder?

x