Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在循环中获得商业明星评级_Php_Wordpress_Woocommerce - Fatal编程技术网

Php 在循环中获得商业明星评级

Php 在循环中获得商业明星评级,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我有一个为我的WooCommerce商店页面构建的自定义模板,它按类别为不同的部分拉入产品 我需要知道如何将每个产品的星级评分纳入循环。我搜索了几个小时,结果一无所获 你的意思是这样的吗 global $product; echo $product->get_rating_html(); 我能够回答我自己的问题。下面是如何在循环中获得明星收视率 首先使用以下代码: <?php if ($average = $product->get_average_rating())

我有一个为我的WooCommerce商店页面构建的自定义模板,它按类别为不同的部分拉入产品


我需要知道如何将每个产品的星级评分纳入循环。我搜索了几个小时,结果一无所获

你的意思是这样的吗

global $product;
echo $product->get_rating_html();

我能够回答我自己的问题。下面是如何在循环中获得明星收视率

首先使用以下代码:

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

如何在没有全局变量$product的情况下获得平均评级。我有产品id。
<ul class="woocommerce">
<li>
    <?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; ?>
</li>
</ul>
    .woocommerce {
        .star-rating {
      width: 110px !important;
      height: 30px !important;
      float: left;
      &:before {
        font-size: 20px;
      }
      span {
        &:before {
          font-size: 20px;
          color: #ffa500;
        }
      }
    }