Hello there,
hope you are doing well
To achieve what you need in category pages, you have to add the following code to the functions.php file of your active theme:
remove_filter( 'woocommerce_product_get_rating_html', array( YITH_WooCommerce_Advanced_Reviews::get_instance(), 'get_product_rating_html' ), 99 );
if ( ! function_exists( 'get_product_rating_html' ) ) {
function get_product_rating_html( $rating_html, $rating ) {
global $product;
$rating_html = '';
if ( ! $product ) {
return $rating_html;
}
$rating = YITH_WooCommerce_Advanced_Reviews::get_instance()->get_average_rating( yit_get_prop( $product, 'id' ) );
if ( $rating >= 0 ) {
$rating_html = '<div class="star-rating" title="' . sprintf( __( 'Rated %s out of 5', 'yith-woocommerce-advanced-reviews' ), $rating ) . '">';
$rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . __( 'out of 5', 'yith-woocommerce-advanced-reviews' ) . '</span>';
$rating_html .= '</div>';
}
return $rating_html;
}
add_filter( 'woocommerce_product_get_rating_html', 'get_product_rating_html', 10, 2 );
}
To get these changes also in your product pages, you will need to override a plugin template. We will tell you the steps you have to follow to achieve this:
1. Copy the ywar-rating.php (found in yith-woocommerce-advanced-reviews/templates
) template into your theme in the following path: wp-content/themes/your_active_theme/woocommerce
2. Open this template from your theme and replace the line 23 with the following code: if ( $rating_count >= 0 ) : ?>
Let me know any news, please.
Have a nice day!
-
This reply was modified 1 year, 11 months ago by
YITHEMES.
Awesome, thank you, everything is working as required!
Just one moment – is it possible to add any changes in the code you provided for the functions.php file to make visible stars and a reviews count near it – ⭐⭐⭐⭐⭐ (12 reviews) on a product category page (just the same as it showing on a single product page) ?
If you can share the changes to make in the functions.php code you provided earlier it would be really great!
Thank you a lot with all your help!
Regards
Awesome, thank you, everything is working as required!
Just one moment – is it possible to add any changes in the code you provided for the functions.php file to make visible stars and a reviews count near it – ⭐⭐⭐⭐⭐ (12 reviews) on a product category page (just the same as it showing on a single product page) ?
If you can share the changes to make in the functions.php code you provided earlier it would be really great!
Thank you a lot with all your help!
Regards
Hello there,
hope you are doing well!
In order to display a review count near the review stars also in your category pages, you have to replace the code (in functions.php file) we sent you previously with the following one:
remove_filter( 'woocommerce_product_get_rating_html', array( YITH_WooCommerce_Advanced_Reviews::get_instance(), 'get_product_rating_html' ), 99 );
if ( ! function_exists( 'get_product_rating_html' ) ) {
function get_product_rating_html( $rating_html, $rating ) {
global $YWAR_AdvancedReview;
global $product;
$rating_html = '';
$product_id = yit_get_prop( $product, 'id' );
$review_count = count( $YWAR_AdvancedReview->get_product_reviews( $product_id ) );
if ( ! $product ) {
return $rating_html;
}
$rating = YITH_WooCommerce_Advanced_Reviews::get_instance()->get_average_rating( yit_get_prop( $product, 'id' ) );
if ( $rating >= 0 ) {
$rating_html = '<div class="star-rating" title="' . sprintf( __( 'Rated %s out of 5', 'yith-woocommerce-advanced-reviews' ), $rating ) . '">';
$rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . __( 'out of 5', 'yith-woocommerce-advanced-reviews' ) . '</span>';
if ( comments_open() ) {
?>
<a href="" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'yith-woocommerce-advanced-reviews' ), '<span itemprop="reviewCount" class="count">' . $review_count . '</span>' ); ?>)</a>
<?php
}
$rating_html .= '</div>';
}
return $rating_html;
}
add_filter( 'woocommerce_product_get_rating_html', 'get_product_rating_html', 10, 2 );
}
Let us know any news, please.
Have a nice day!
Thank you!
Strange that not every product showing the Review count, some of the products does not show on category page, don’t you know why that may happen?
Regards
Work fine on shop-page.
Is this also possible for a productpage?