简体   繁体   English

隐藏评论部分的用户评论电子邮件

[英]Hide User Review Email from Comment Section

I'm trying to prevent Woocommerce from displaying customer email as the product reviewer's name. 我试图阻止Woocommerce将客户电子邮件显示为产品审阅者的姓名。 So far all attempts to manually change it in the WP Admin User interface have failed. 到目前为止,所有在WP Admin User界面中手动更改它的尝试都失败了。 Figured I'd try out php here. 想通了,我会在这里尝试PHP。

Found this code that's rendering the name in templates/single-product/review-meta.php: 在template / single-product / review-meta.php中找到了呈现名称的代码:

    <strong class="woocommerce-review__author"><?php comment_author(); ?></strong> <?php

I need to modify the comment_author(), so I added a filter (I'm new to php, btw). 我需要修改comment_author(),因此添加了一个过滤器(我是php,btw的新手)。

add_filter( 'comment_author', 'private_comment_author', 10, 0 );
function private_comment_author() {
    return $comment_ID;
}

The "$comment_ID" is a filler. “ $ comment_ID”是一个填充符。 How can I return the users public display name, or first and last name? 如何返回用户的公共显示名称或名字和姓氏?

The filter passes the user name string so you can use that to get any information you want about the user like first name. 过滤器传递用户名字符串,以便您可以使用它来获取您想要的有关用户的任何信息,例如名字。

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 );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM