WooCommerce: Get/Edit Logged in Username @ Checkout
On a recent job, a client asked me to get the logged in username in WooCommerce. Interesting task! He needed to show that on the checkout form page and also on the order email. Actually, this is quite simple to do and can be used for several applications.
PHP snippet: get logged in username and show it on the WooCommerce checkout page in a billing field
Please let me know in the comments if everything went as expected. I would be happy to revise the snippet if you report otherwise (please provide screenshots). I have tested this code with Storefront theme, the WooCommerce version listed above and a WordPress-friendly hosting.
Check out these free video tutorials. You can learn how to customize WooCommerce without unnecessary plugins, how to properly configure the WooCommerce plugin settings and even how to master WooCommerce troubleshooting in case of a bug!
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.
14 thoughts on “WooCommerce: Get/Edit Logged in Username @ Checkout”
Hi, thank you for this snippet. This works great on the checkout page, but it doesn’t come through on the order email… Is there a way to do this?
Hi Matt, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
Hi, if i need to add a field or a title on the div “woocommerce-account-fields” when the user is not login in the chechout page what can i do?
Hi Carlotta, thanks so much for your comment! Yes, this is definitely possible, but I’m afraid it’s custom work. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding!
It’s working. How do you get the field to be apart of the WooCommerce ‘Order Details?’
Hello Dan, thanks so much for your comment! Yes, this is possible – unfortunately this is custom work and I cannot provide a complementary solution here via the blog comments. If you’d like to get a quote, feel free to contact me here. Thanks a lot for your understanding! ~R
Thank you very much. Works perfectly
Thanks for the snippit. Is it possible to make the field read only?
Hi Ian – thanks so much for your comment! Yes, the woocommerce_form_field() function has an attribute ‘custom_attributes’ that can be used to make the input readonly. Hope this helps!
This still works great in the most recent version of Woo. One quick question I have is using this snippet, how can I define where it shows up in the form. Right now it puts it at the bottom of the checkout form. Is it possible to say put it after email address or in a specific order?
Hey Jamie, thanks so much for your comment! Take a look at https://businessbloomer.com/woocommerce-move-reorder-fields-checkout-page/, you could add that as a new field and then define the priority maybe 🙂
how do you get this added tot he email as well?
Kelly, thanks so much for your comment! Maybe this video tutorial might help: https://businessbloomer.com/customize-emails-woocommerce/