Skip to content

Instantly share code, notes, and snippets.

@robin-scott
Created April 18, 2018 09:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robin-scott/313adf76dc7a49478d3d1277533afcd7 to your computer and use it in GitHub Desktop.
Save robin-scott/313adf76dc7a49478d3d1277533afcd7 to your computer and use it in GitHub Desktop.
Change review author to not show full name, WooCommerce
// Add this to child theme functions.php to change the way reviews display in WooCommerce to not show full name.
// Details here: https://silicondales.com/tutorials/woocommerce/woocommerce-change-review-author-display-name-username/
// 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){
$user=get_userdata($comment->user_id);
$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;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment