将以下代码添加到函数中。php
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 );
}
然后再添加以下行以获得评级计数
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;
}