Show product star ratings and count below the price in Woocommerce archive pages [closed]

送分小仙女□ 提交于 2019-11-29 08:53:14

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 );
}

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


Addition to get the rating count:

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

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!