admin管理员组文章数量:1327849
On my WooCommerce site I am trying to output the star rating for a product that is reviewed. Instead, it outputs this:
Rated 3.38 out of 5 based on 8 customer ratings
What am I missing with the following code?
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average = $product->get_average_rating();
echo wc_get_rating_html( $average, $rating_count );
When I switch from my custom theme to default WordPress theme, the ratings then show.
On my WooCommerce site I am trying to output the star rating for a product that is reviewed. Instead, it outputs this:
Rated 3.38 out of 5 based on 8 customer ratings
What am I missing with the following code?
$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average = $product->get_average_rating();
echo wc_get_rating_html( $average, $rating_count );
When I switch from my custom theme to default WordPress theme, the ratings then show.
Share Improve this question edited Jan 9, 2018 at 13:02 Zach Smith asked Jan 9, 2018 at 12:57 Zach SmithZach Smith 5962 gold badges9 silver badges23 bronze badges3 Answers
Reset to default 5Suffered with same problem. Finally after lot of search and trial I came up with this solution.
This gets the template where the rating is displayed from. But it displays like this: Rated 4.50 out of 5 based on 2 customer ratings (2 customer reviews)
<div class="rating-custom">
<?php wc_get_template( 'single-product/rating.php' ); ?>
</div>
Then paste this css code in a custom css.
/*star rating for products*/
.rating-custom div.product .woocommerce-product-rating {
margin-bottom: 1.618em;
}
.rating-custom .woocommerce-product-rating .star-rating {
margin: .5em 4px 0 0;
float: left;
}
.rating-custom .woocommerce-product-rating::after, .rating-custom .woocommerce-product-rating::before {
content: ' ';
display: table;
}
.rating-custom .woocommerce-product-rating {
line-height: 2;
}
.rating-custom .star-rating {
float: right;
overflow: hidden;
position: relative;
height: 1em;
line-height: 1;
font-size: 1em;
width: 5.4em;
font-family: star;
}
.rating-custom .star-rating::before {
content: '\73\73\73\73\73';
color: #d3ced2;
float: left;
top: 0;
left: 0;
position: absolute;
}
.rating-custom .star-rating {
line-height: 1;
font-size: 1em;
font-family: star;
}
.rating-custom .star-rating span {
overflow: hidden;
float: left;
top: 0;
left: 0;
position: absolute;
padding-top: 1.5em;
}
.rating-custom .star-rating span::before {
content: '\53\53\53\53\53';
top: 0;
position: absolute;
left: 0;
}
.rating-custom .star-rating span {
overflow: hidden;
float: left;
top: 0;
left: 0;
position: absolute;
padding-top: 1.5em;
}
Output:
Just make sure the parent container contains the css class woocommerce
like following:
<div class="woocommerce">
<?php wc_single_product_ratings(); ?>
</div>
Perhaps, it is easier to integrate an existing solution to achieve what you want. See image below:
I recently found TrustFeed reviews for WooCommerce, it helped me to replace the basic and boring WooCommerce reviews forms with an advanced and dynamic rating and reviews solution that actually inspire shoppers to buy more!
The plugin is free and can be dowloaded via official WordPress plugin repository:
https://wordpress/plugins/trustfeed-reviews-and-customer-feedback-for-woocommerce/
It comes with special features to help honest online businesses to collect and showcase customer reviews to boost sales, conversions, trust and social proof.
Some special features are:
- Create custom satisfaction surveys
- Star Ratings
- Dynamic Tags
- Text Reviews
- More coming…
- Send Mail After Purchase emails to encourage shoppers to leave reviews.
- Collect reviews at scale.
- Showcase reviews on key conversion points of your website.
- Display your reviews in an useful, responsive and customizable format.
- Moderate and manage feedback/reviews.
- Create a mini-site to increase your SEO with User Generated Content
- Customize widget’s look and feel.
- Learn from data driven insights
Thee good news. You can start for free!
- To learn more about TrustFeed you can visit www.trustfeed.co
- To view the admin panel, just login at https://admin.trustfeed.co and create a free account.
本文标签: WooCommerce showing star rating review instead of text review string
版权声明:本文标题:WooCommerce showing star rating review instead of text review string 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742218991a2435092.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论