在星级旁边显示 woocommerce 评论数 [英] Display woocommerce review count next to star rating

查看:25
本文介绍了在星级旁边显示 woocommerce 评论数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有评论的 Woocommerce 星级评分.

Woocommerce star rating without reviews count.

修改 Woocommerce 星级和评论数.

Modified Woocommerce star rating with reviews count.

推荐答案

Woocommerce 已经在单个产品页面的星级旁边显示评论计数.但在商店和档案页面上,它只显示星级.按照以下步骤,即使在商店和档案页面上也能显示星级评分.

Woocommerce already displays reviews count next to star rating in single product page. But on shop and archives page it displays only star rating. Follow the below steps to display star rating count even on shop and archives pages.

步骤 1) 在主题的根目录中创建一个新文件夹并将其命名为woocommerce"

Step 1) Create a new folder in your theme’s root and name it ‘woocommerce’

步骤 2) 在新创建的 ‘woocommerce’ 文件夹中创建一个新文件夹并将其命名为 ‘loop’

Step 2) Create a new folder in the newly created ‘woocommerce’ folder and name it ‘loop’

步骤 3) 将rating.php"文件添加到新创建的loop"文件夹中

现在你的目录看起来像这样

Now your directory would look something like this

/public_html/wp-content/themes/YOUR-THEME/woocommerce/loop

/public_html/wp-content/themes/YOUR-THEME/woocommerce/loop

将以下代码添加到新创建的rating.php"中,并根据需要进行自定义.

Add the below code to the newly created ‘rating.php’ and customize it according to your need.

<?php
/**
 * Loop Rating
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/loop/rating.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     3.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

global $product;

if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
    return;
}

$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();

if ( $rating_count >= 0 ) : ?>

            <?php echo wc_get_rating_html($average, $rating_count); ?>
        <?php if ( comments_open() ): ?><a href="<?php echo get_permalink() ?>#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s',$review_count,'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>


<?php endif; ?>

如果这不起作用

在woocommerce"文件夹中添加templates"文件夹,然后在templates"文件夹中添加loop"文件夹.

Add ‘templates’ folder in ‘woocommerce’ folder and then add ‘loop’ folder in ‘templates’ folder.

现在目录看起来像这样

/public_html/wp-content/themes/YOUR-THEME/woocommerce/templates/loop

/public_html/wp-content/themes/YOUR-THEME/woocommerce/templates/loop

这篇关于在星级旁边显示 woocommerce 评论数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆