Have you ever wanted to change the way that WooCommerce reviews are displayed in your store?
The code below, when added to your theme’s functions.php file will allow you to change comment author display from username to first name and last initial with a . after it.
Please note, you can always change this to suit your needs! The code should be a good starting point, however.
Also note, this may change how regular comment authors names display, but only if they are registered and logged in user’s comments…
Change WooCommerce Review Author Display Name from Username to “FirstName L.”
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Leave a comment below if this helped you get this done. If you’d like clarification, feel free to ask in the comments, too. If you want to book us to complete some WooCommerce customisation or other, contact us!
Happy woocommercing…
16 thoughts on “How to Change the Review Author Display Name in WooCommerce (stop using full name!)”
Hi there,
This certainly works but it also changes the way customer names are displayed for the backend admin which makes searching for a customer or adding a customer order in the backend very difficult.
It shouldn’t change the way customer names are displayed in admin. This code changes the “comment author” part on the *front end* of the website. It does not alter the way usernames / firstnam last name are shown in WooCommerce. Perhaps you installed something else that does that?
Can confirm I just installed this function on this website (it altered my name, but the username / buyer name in woocommerce remains the same as it was, first name, last name.).
My comment author name, though, showed as Robin S., as this code intended.
Tested and works. You have something else changing user name in wooocommerce / WP admin!
I will have to investigate what is causing that to change in the backend but your code certainly works well for the front end.
Do you know how I could expand on your code to show the first name and last name initial for everyone except administrators? I would like to be able to display replies as Customer Service – of course your code currently works as promised and shows Customer S.
This worked perfectly but for some reason if the Full First and Last name is not already chosen as the Display Publicly then it shows “Anonymous” which is not good. If someone has 10k users you’d be sitting there all day.
You would probably need a script to force the Display name to use First & Last
Yes this is outside of the scope of this function. If you don’t have names set, then this function wouldn’t work. The object of this little snippet is to stop showing full name of a buyer in reviews, which people can get antsy about (I don’t necessarily want my full name to show up – it might put me off posting a review at all!). Its most appropriate when reviews are left by genuine buyers only.
This script quite literally sets the author to “Anonymous” if the user did not have a user account (i.e. on guest posted reviews). You can change “anonymous” to be something else, like “guest review” or make it use the comment name details provided.
That’s beyond the scope of this snippet, but it shouldn’t be too hard to figure out… alas I’m deep in some other tasks right now, but another commentor might post this up… or I’ll circle back later and see what I can dream up!
Thanks for the comment – have pushed this code into a Gist, which should work a lot better. Its something we’ve been doing site-wide, but your comment did help to highlight one that got away 🙂
Hello, thank you very much for your contribution. I want to get the first letter of the author’s name and surname. Then I want to show this in the comments too. How should I make a change in the code? For example; Author: Robin Scott Name in the comments: It should be R **** S ***. Thank you in advance for your interest.
Sorry for the slow reply – this one popped up in spam filter for some reason.
That would require some other code – you’d need to do a little more to get the output you want, in line 12 (it’s commented “this is the line you need to change”). You can also see where the “anonymous” part is set, too.
You can see an example of how to do a similar thing, here:
I’ve tried this code and it works very well but an error appears above the name in debug mode : “Notice: Undefined variable: comment_ID in /www/websitefolder/public/wp-content/themes/hello-elementor-child/functions/woocommerce.php on line 190
Hi there,
This certainly works but it also changes the way customer names are displayed for the backend admin which makes searching for a customer or adding a customer order in the backend very difficult.
Any workaround for that?
Hi Leanne,
It shouldn’t change the way customer names are displayed in admin. This code changes the “comment author” part on the *front end* of the website. It does not alter the way usernames / firstnam last name are shown in WooCommerce. Perhaps you installed something else that does that?
Robin
Can confirm I just installed this function on this website (it altered my name, but the username / buyer name in woocommerce remains the same as it was, first name, last name.).
My comment author name, though, showed as Robin S., as this code intended.
Tested and works. You have something else changing user name in wooocommerce / WP admin!
Thanks for your reply Robin 🙂
I will have to investigate what is causing that to change in the backend but your code certainly works well for the front end.
Do you know how I could expand on your code to show the first name and last name initial for everyone except administrators? I would like to be able to display replies as Customer Service – of course your code currently works as promised and shows Customer S.
Appreciate your advice.
I can think of an easy fix. Set Customer Service as the first name with no last name.
Where do you actually Place this code…??
Hi Jake,
This code should be placed into functions.php file for your theme or child theme. Or you could put it into a helper plugin.
Regards,
Robin
This worked perfectly but for some reason if the Full First and Last name is not already chosen as the Display Publicly then it shows “Anonymous” which is not good. If someone has 10k users you’d be sitting there all day.
You would probably need a script to force the Display name to use First & Last
Hi Stef,
Yes this is outside of the scope of this function. If you don’t have names set, then this function wouldn’t work. The object of this little snippet is to stop showing full name of a buyer in reviews, which people can get antsy about (I don’t necessarily want my full name to show up – it might put me off posting a review at all!). Its most appropriate when reviews are left by genuine buyers only.
This script quite literally sets the author to “Anonymous” if the user did not have a user account (i.e. on guest posted reviews). You can change “anonymous” to be something else, like “guest review” or make it use the comment name details provided.
That’s beyond the scope of this snippet, but it shouldn’t be too hard to figure out… alas I’m deep in some other tasks right now, but another commentor might post this up… or I’ll circle back later and see what I can dream up!
Good luck!
Thanks for the tip
Works perfectly. There are a couple of fancy quotes in the snippet though.
Thank you!
Thanks for the comment – have pushed this code into a Gist, which should work a lot better. Its something we’ve been doing site-wide, but your comment did help to highlight one that got away 🙂
Hello, thank you very much for your contribution.
I want to get the first letter of the author’s name and surname. Then I want to show this in the comments too. How should I make a change in the code?
For example;
Author: Robin Scott
Name in the comments:
It should be R **** S ***.
Thank you in advance for your interest.
Hi Carl,
Sorry for the slow reply – this one popped up in spam filter for some reason.
That would require some other code – you’d need to do a little more to get the output you want, in line 12 (it’s commented “this is the line you need to change”). You can also see where the “anonymous” part is set, too.
You can see an example of how to do a similar thing, here:
https://stackoverflow.com/questions/16090072/replace-all-characters-of-string-to-asterisks-except-first-and-last-characters-i/16090349
Using a function like this, you could do what you’re looking for, and combine into my Gist for a 100% result.
Hello !
Thanks for this contribution 🙂
I’ve tried this code and it works very well but an error appears above the name in debug mode :
“Notice: Undefined variable: comment_ID in /www/websitefolder/public/wp-content/themes/hello-elementor-child/functions/woocommerce.php on line 190
Any idea on a way to solve this please ?
Thank you in advance for your help !
Change the filter to:
add_filter(‘get_comment_author’, ‘my_comment_author’, 10, 3);
And the function to:
function my_comment_author($author, $comment_ID, $comment)
It should remove the warnings