Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save tdmrhn/145da49126e509a1808b6fa122998d20 to your computer and use it in GitHub Desktop.

Select an option

Save tdmrhn/145da49126e509a1808b6fa122998d20 to your computer and use it in GitHub Desktop.
Woocommerce Reviews Author Name Display Formating
<?php
add_filter( 'get_comment_author', function ( $author, $comment_id, $comment ) {
if ( ! $comment || get_post_type( $comment->comment_post_ID ) !== 'product' ) {
return $author;
}
if ( $comment->user_id ) {
$user = get_userdata( $comment->user_id );
$first = $user->first_name;
$last = $user->last_name;
if ( ! $first ) {
return $author;
}
$initial = $last ? ' ' . strtoupper( $last[0] ) . '.' : '';
return $first . $initial;
}
return __( 'Anonymous', 'woocommerce' );
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment