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 My Account WordPress Dashboard

WooCommerce: Sync Billing Name & WP User Name

Last Revised: Feb 2022

STAY UPDATED

When someone places an order via the WooCommerce checkout, there is a function (process_customer) that saves the checkout first & last name to the customer Billing address (WooCommerce). The same function also overwrites that same WP user first & last name (WordPress).

The same happens when someone updates the Billing address via the My Account edit address tab. There is a WooCommerce function (save_address) that copies Billing first & last name to the WP user first & last name.

You’d think that was sufficient to keep billing names and WP user names in sync – well, nope. You can also update billing first & last name from the user edit profile page (WP dashboard). In such case, WP user first & last name is NOT updated, and billing and user names are not in sync.

Today, we’ll study some code to make that happen, so that you never have to worry again about inconsistencies. Enjoy!

Let’s suppose my name is Lawrence Melogli. WP User and Billing User are in sync. But if I go edit the Billing address via my WP User Profile page, and enter “Rodolfo” as first name, the WP User remains unchanged. In this article, we’ll fix that.

PHP Snippet: Sync Billing First & Last Name With User First & Last Name @ WP Edit User Profile

/**
 * @snippet       Copy Billing to User @ WP User Edit Page
 * @how-to        businessbloomer.com/woocommerce-customization
 * @author        Rodolfo Melogli, Business Bloomer
 * @testedwith    WooCommerce 6
 * @community     https://businessbloomer.com/club/
 */

add_filter( 'pre_user_first_name', 'bbloomer_sync_user_edit_profile_edit_billing_first_name' );

function bbloomer_sync_user_edit_profile_edit_billing_first_name( $first_name ) {
    if ( isset( $_POST['billing_first_name'] ) ) {
        $first_name = $_POST['billing_first_name'];
    }
    return $first_name;
}

add_filter( 'pre_user_last_name', 'bbloomer_sync_user_edit_profile_edit_billing_last_name' );

function bbloomer_sync_user_edit_profile_edit_billing_last_name( $last_name ) {
    if ( isset( $_POST['billing_last_name'] ) ) {
        $last_name = $_POST['billing_last_name'];
    }
    return $last_name;
}

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 Second Description @ Product Category Pages
    In terms of SEO, if you’re trying to rank your product category pages, you really need to make the most of the default WooCommerce product…
  • 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…

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 Stop Spam Orders on Free Products
  • 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

Latest Comments

  1. Rodolfo Melogli on WooCommerce Visual Hook Guide: Checkout Page
  2. Rodolfo Melogli on WooCommerce: Prevent Duplicate Orders
  3. Rodolfo Melogli on WooCommerce: Hide Checkout Fields if Virtual Product @ Cart

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