Created
April 18, 2018 09:55
-
-
Save robin-scott/313adf76dc7a49478d3d1277533afcd7 to your computer and use it in GitHub Desktop.
Change review author to not show full name, WooCommerce
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
// 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