显示产品星级,并计入Woocommerce存档页面中的价格以下 [英] Show product star ratings and count below the price in Woocommerce archive pages

查看:115
本文介绍了显示产品星级,并计入Woocommerce存档页面中的价格以下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在woocommerce存档页面中,我想将评级下调至价格下.

In woocommerce archive pages, I would like to move the ratings under the price.

有可能吗?我该怎么做?

Is that possible? How can I make it?

这就是我想要的:

感谢您的帮助.

我的网站链接

推荐答案

以下功能会将等级降低到Woocommerce档案页面中的价格以下:

The following function will move ratings below the price in Woocommerce archives pages:

add_action('woocommerce_after_shop_loop_item_title','change_loop_ratings_location', 2 );
function change_loop_ratings_location(){
    remove_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_rating', 5 );
    add_action('woocommerce_after_shop_loop_item_title','woocommerce_template_loop_rating', 15 );
}

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

添加以获得评分计数:

add_filter( 'woocommerce_product_get_rating_html', 'loop_product_get_rating_html', 20, 3 );
function loop_product_get_rating_html( $html, $rating, $count ){
    if ( 0 < $rating && ! is_product() ) {
        global $product;
        $rating_cnt = array_sum($product->get_rating_counts());
        $count_html = ' <div class="count-rating">' . $rating_cnt .'</div>';

        $html       = '<div class="container-rating"><div class="star-rating">';
        $html      .= wc_get_star_rating_html( $rating, $count );
        $html      .= '</div>' . $count_html . '</div>';
    }
    return $html;
}

还需要一些其他CSS样式(可能是html结构更改)

Some additional CSS styling will be needed (and may be html structure changes)

代码进入您的活动子主题(或活动主题)的function.php文件中.经过测试,可以正常工作.

Code goes in function.php file of your active child theme (or active theme). Tested and works.

这篇关于显示产品星级,并计入Woocommerce存档页面中的价格以下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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