I have a woocommerce store and I want to add star ratings to each of the products when you see their thumbnails. I already have the stars in the big product view but I want them to display below each thumbnail like in most ecommerce stores like timberland.com. I know i can use css to disable items from view but not add them. Any thoughts?
相关问题
- Display product ACF field value in Woocommerce tra
- Adding a custom button after add to cart button in
- How to add a “active” class to a carousel first el
- Setting custom order statuses as valid for payment
- change the font size in tag cloud
相关文章
- wordpress新增页面如何个性化设置
- select query in wordpress
- Get WooCommerce featured products in a WP_Query
- Woocommerce update shipping methods in checkout vi
- Change order status just after payment in WooComme
- Publishing or uploading failed. Error message: “Th
- Facebook Login With WP JWT Auth
- Wordpress development process
With those functions (or the shorter one below, which outputs the same HTML), you manage to output the rating in numbers, reusing Woocommerce's functions completely:
Then you need to style it to show the stars. For a rating of 3 out of 5 stars, Woothemes does it like this (the trick is in the width and :before of the corresponding CSS):
HTML (output by Woocommerce):
And the CSS (there may be some redundant lines in here):
Hope that helps!
You can put this into your themes functions.php file:
Note that you may need to change
woocommerce_after_shop_loop_item
to a different hook depending on your design and where exactly you want the stars to show up.This page lists WooCommerce action hooks: http://wcdocs.woothemes.com/codex/extending/hooks/ . I don't see any hooks associated with the thumbnail specifically, but you may try
woocommerce_after_shop_loop_item_title
orwoocommerce_after_shop_loop_item
.(This function is essentially copied from WooCommerce's single-product-reviews.php)
As of WooCommerce 3.0+ this is the correct code:
The get_rating_html() method on the product object has been deprecated.
More information here: https://docs.woocommerce.com/wc-apidocs/function-wc_get_rating_html.html
There's actually a much more terse way to handle this. Just use the built-in functions that Woocommerce has built out:
I've confirmed that this works for me.