我试图阻止Woocommerce显示客户电子邮件作为产品评论员的名字。到目前为止,在WP Admin User界面中手动更改它的所有尝试都失败了。想我会在这里试试php。
发现此代码在templates / single-product / review-meta.php中呈现名称:
<strong class="woocommerce-review__author"><?php comment_author(); ?></strong> <?php
我需要修改comment_author(),所以我添加了一个过滤器(我是php,btw的新手)。
add_filter( 'comment_author', 'private_comment_author', 10, 0 );
function private_comment_author() {
return $comment_ID;
}
“$ comment_ID”是填充符。如何返回用户的公共显示名称或名字和姓氏?
答案 0 :(得分:0)
过滤器传递用户名字符串,以便您可以使用它来获取您想要的有关用户的任何信息,如名字。
function private_comment_author( $user_name ) {
$user = get_user_by( 'login', $user_name );
if( $user )
return $user->first_name . ' ' . $user->last_name;
else
return '';
}
add_filter( 'comment_author', 'private_comment_author', 10, 1 );