- This topic has 15 replies, 3 voices, and was last updated 2 years ago by Fernando.
-
AuthorPosts
-
April 12, 2022 at 9:58 am #2186636Georgi
Hello,
Since I migrated to GP I noticed that now the rating count for products in archive pages isn’t aligned next to the star reviews but it’s below them: https://prnt.sc/fMD2EWot4x8n
I tried different kinds of CSS solutions on the web but none worked with GP :/
Can you help?
Kind regards!
April 12, 2022 at 10:18 am #2186657YingStaffCustomer SupportHi Georgi,
GP doesn’t have the review number added by default, how did you add it?
Based on the current html structure, there isn’t a good way to position the number and stars.
April 12, 2022 at 11:06 am #2186702GeorgiHi Ying,
I’m using the following php code:
if ( ! defined( 'ABSPATH' ) ) { exit; } global $product; if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { return; } $rating_count = $product->get_rating_count(); $review_count = $product->get_review_count(); $average = $product->get_average_rating(); if ( $rating_count >= 0 ) : ?> <?php echo wc_get_rating_html($average, $rating_count); ?> <?php if ( comments_open() ): ?><a href="<?php echo get_permalink() ?>#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s',$review_count,'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?> <?php endif; ?>
Nothing can be done :/ ?
April 12, 2022 at 11:30 am #2186724YingStaffCustomer SupportHow did you add the code?
April 12, 2022 at 12:17 pm #2186754GeorgiCreated a rating.php file with the code and added it to /public_html/wp-content/themes/YOUR-THEME/woocommerce/loop
April 12, 2022 at 3:53 pm #2186877YingStaffCustomer SupportDo you mean you edited GP’s theme file?
If so, it’s not a good idea, the change will lose when you update GP.
And I don’t recall there’s a Woocommerce folder under GP’s theme folder, are you sure?
I would recommend do this:
1. Go to appearance > elements, create a Hook element, add this code and check the Execute PHP box.
<?php global $product; if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { return; } $rating_count = $product->get_rating_count(); $review_count = $product->get_review_count(); $average = $product->get_average_rating(); if ( $rating_count >= 0 ) : ?> <?php echo '<div class="raiting-and-review-count">'.wc_get_rating_html($average, $rating_count); ?> <?php if ( comments_open() ): ?><a href="<?php echo get_permalink() ?>#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s',$review_count,'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a></div><?php endif ?> <?php endif; ?>
2. Select
woocommerce_after_shop_loop_item_title
as the hook, set product archive as location.3. Add this CSS to align the star and the number:
.raiting-and-review-count { display: flex; justify-content: center; }
April 13, 2022 at 10:06 am #2187893GeorgiHello,
Thanks for the suggestion.
I tried it but it put the stars under the price https://prnt.sc/0SxX16tXaXr8
The CSS does a great job at aligning the number to the stars, but the problem is the location of the stars now πApril 13, 2022 at 10:49 am #2187927YingStaffCustomer Supportbut the problem is the location of the stars now
Try set the element’s priority to
2
instead of10
.Let me know π
April 13, 2022 at 10:54 am #2187930GeorgiYay, it moved it π
But it’s a little too close to the title, can there be a little space between the stars and the title like there is between the price? https://prnt.sc/hRZ-cdRFLXTQ
April 13, 2022 at 11:05 am #2187941YingStaffCustomer SupportAdd one line to the CSS:
.raiting-and-review-count { display: flex; justify-content: center; padding-top:15px; }
April 13, 2022 at 11:47 am #2187974GeorgiAwesome! Thank you, Ying!
April 13, 2022 at 11:51 am #2187979YingStaffCustomer SupportNo problem π
April 18, 2022 at 10:07 pm #2192977GeorgiHello,
Sorry to bother, I thought everything was working but just now I noticed that I get ratings score even for products without reviews – https://prnt.sc/lPjwORwFY-qA
Any idea how to hide them?
April 18, 2022 at 10:33 pm #2192986Fernando Customer SupportHi Georgi,
Can you kindly modify the code provided by Ying in step 1 above to this:
<?php global $product; if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { return; } $rating_count = $product->get_rating_count(); $review_count = $product->get_review_count(); $average = $product->get_average_rating(); if ( $rating_count > 0 ) : ?> <?php echo '<div class="raiting-and-review-count">'.wc_get_rating_html($average, $rating_count); ?> <?php if ( comments_open() ): ?><a href="<?php echo get_permalink() ?>#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s',$review_count,'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a></div><?php endif ?> <?php endif; ?>
Kindly let us know how it goes. π
April 19, 2022 at 9:50 am #2193792GeorgiWorked like a charm, thanks Fernando! π
-
AuthorPosts
- You must be logged in to reply to this topic.