How to Change the Review Author Display Name in WooCommerce (stop using full name!)

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.”

// Add this to child theme functions.php to change the way reviews display in WooCommerce to not show full name.
// Details here:
// By Robin Scott for Silicon Dales
add_filter('get_comment_author', 'my_comment_author', 10, 1);
function my_comment_author( $author = '' ) {
// Get the comment ID from WP_Query
$comment = get_comment( $comment_ID );
if (!empty($comment->comment_author) ) {
if($comment->user_id > 0){
$author=$user->first_name.' '.substr($user->last_name,0,1).'.'; // this is the actual line you want to change
} else {
$author = __('Anonymous');
} else {
$author = $comment->comment_author;
return $author;
view raw functions.php hosted with ❤ by GitHub

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…

14 thoughts on “How to Change the Review Author Display Name in WooCommerce (stop using full name!)

  1. 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?

    1. 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?


      1. 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!

  2. 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.

    1. I can think of an easy fix. Set Customer Service as the first name with no last name.

  3. Where do you actually Place this code…??

    1. 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.



  4. 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

    1. 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!

  5. Thanks for the tip

  6. Works perfectly. There are a couple of fancy quotes in the snippet though.

    Thank you!

    1. 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 ๐Ÿ™‚

  7. 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.

    1. 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:

      Using a function like this, you could do what you’re looking for, and combine into my Gist for a 100% result.

Leave a Reply

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