我在wordpress网站上有一个产品供应商woocommerce设置.人们可以注册并添加自己的产品,这些产品只是自定义帖子类型等,购买这些产品的其他人可以查看它们.评论是WordPress自定义帖子类型产品的评论模板的一部分.我正在使用以下代码显示购买产品的人(自定义帖子类型)的单评(wordpress评论):
我想要工作的主要部分是通过woocommerce插件添加的星级评分:
echo('Rating: <div class="star-rating" itemprop="reviewRating" itemscope itemtype="http://schema.org/Rating"><span style="width:' . ( get_comment_meta( $comment->comment_ID, 'rating', true ) / 5 ) * 100 . '%"><strong itemprop="ratingValue">' . get_comment_meta( $comment->comment_ID, 'rating', true ) . '</strong></span></div><br />');
Run Code Online (Sandbox Code Playgroud)
完整代码:
<?php
if ( is_user_logged_in() ) {
$user_id = get_current_user_id();
$args = array(
'orderby' => 'date',
'post_type' => 'product',
'number' => '4',
'post_author' => $user_id
);
$comments = get_comments($args);
foreach($comments as $comment) :
echo '<div>';
echo('Review By: ' . $comment->comment_author . '<br />');
echo('Product: ' . '<a …Run Code Online (Sandbox Code Playgroud)