【问题标题】:Woo commerce star rating display only when greater than 1Woocommerce 星级仅在大于 1 时显示
【发布时间】:2017-12-29 16:56:50
【问题描述】:

我正在尝试在 woocommerce 中使用星级评分系统,但遇到了一些问题。它在有评级时显示完美,但如果没有评级,我希望它不显示,我尝试了一些不同的选项,但似乎都没有。

我用来显示它的基本代码是:

<div class="star-rating">
<?php if ($average = $product->get_average_rating()) : ?>
<?php echo '<div class="star-rating" title="'.sprintf(__( 'Rated %s 
out of 5', 'woocommerce' ), $average).'"><span style="width:'.( ( 
$average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" 
class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' 
).'</span></div>'; ?>
<?php endif; ?>
</div>  

它现在显示两个评级为未评级的项目,如果评级不存在,任何帮助将不胜感激。

【问题讨论】:

  • if there are no ratings ->表示0还是空?
  • 正确。我尝试添加

标签: php wordpress woocommerce


【解决方案1】:

我假设no-ratings 表示0,然后执行以下操作:-

<?php if ($average = $product->get_average_rating()) : ?>
        <?php if($average > 0);?>
        <div class="star-rating">
            <?php echo '<div class="star-rating" title="'.sprintf(__( 'Rated %s out of 5', 'woocommerce' ), $average).'"><span style="width:'.( ( $average / 5 ) * 100 ) . '%"><strong itemprop="ratingValue" class="rating">'.$average.'</strong> '.__( 'out of 5', 'woocommerce' ).'</span></div>'; ?>
        </div>
    <?php endif; ?>
<?php endif; ?>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多