gpt4 book ai didi

php - 在星级评级旁边显示 woocommerce 评论计数

转载 作者:行者123 更新时间:2023-12-01 19:23:04 25 4
gpt4 key购买 nike

Woocommerce 星级评定,不计评论。

enter image description here

修改了 Woocommerce 星级评分和评论计数。

enter image description here

最佳答案

Woocommerce 已在单个产品页面的星级评定旁边显示评论计数。但在商店和文件页面上它只显示星级。按照以下步骤,甚至可以在商店和文件页面上显示星级计数。

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

第2步)在新创建的“woocommerce”文件夹中创建一个新文件夹并将其命名为“loop”

第3步)将“rating.php”文件添加到新创建的“loop”文件夹中

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

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

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

<?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”文件夹。

现在目录看起来像这样

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

关于php - 在星级评级旁边显示 woocommerce 评论计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46383613/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com