如何在所有页面(而不只是商店页面)上添加星级和计数器?

我正在尝试添加平均星级,并在其旁边添加一个计数器,以显示还剩多少条评论。我将其仅用于我的商店页面,并通过将以下代码添加到主题(醒目的)functions.php文件中来实现了这一点:

add_action( 'woocommerce_after_shop_loop_item_title','gkartikey_woocommerce_template_loop_rating',5 );
if ( ! function_exists( 'gkartikey_woocommerce_template_loop_rating' ) ) {

    /**
     * Display the average rating in the loop.
     */
    function gkartikey_woocommerce_template_loop_rating() {
        wc_get_template( 'loop/rating.php' );
    }
}


add_filter( 'woocommerce_product_get_rating_html',function ( $html,$rating,$count ) {
    global $product;
    if ( $html && is_archive() && $product) {
        $html .= sprintf( '<span>%s</span>',$product->get_rating_count() );
    }

    return $html;
},10,3 );

问题是计数器没有显示在其他页面上,例如我使用Elementor添加产品的主页上。

示例图片Home Page Not Showing Counter Next To Stars

示例图片Shop Page Showing Counter Next To Stars

z145071 回答:如何在所有页面(而不只是商店页面)上添加星级和计数器?

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3040437.html

大家都在问