首页 > 解决方案 > 如何在woocommerce中限制每个产品的一次评论

问题描述

嗨,我想将一条评论限制为来自经过验证的买家的一种产品,

我在几个论坛上搜索过,但到目前为止我还没有成功

我从另一个论坛找到了这段代码

// Check if user has previously commented the post.
global $current_user, $post;

if ( ! is_user_logged_in() ) {
    // Show the comment form if the user is not logged in.
    comment_form();
} else { // The user is logged in...

    // Get the comments for the logged in user.
    $usercomment = get_comments( array (
            'user_id' => $current_user->ID,
            'post_id' => $post->ID,
    ) );

    // If the user has commented, output a message.
    if ( $usercomment ) { 
        echo '<p>Vous avez déjà signé cette pétition. S\'il vous plaît partager avec votre famille et vos amis</p>';
    } else { // Otherwise, show the comment form.
        comment_form(); 
    }
}

但我不知道如何自定义single-product-reviews.php模板文件

代码来自这个论坛的答案

https://wordpress.stackexchange.com/a/137814

在哪一行添加代码?

谢谢

标签: wordpresstemplateswoocommerce

解决方案


推荐阅读