Now my site uses a star rating of this type (in Woocommerce products)

enter image description here

This is not very beautiful, as the star rating (the fact that they are separated), but this is not the problem. You need to make a rating through like / dislike for this example (thumbs up / down) enter image description here

I don’t mind how to do this, because I don’t know if WP rating functions besides wp_star_rating() . In general, I ask for directions (and maybe solutions) where to go.

WordPress 4.9.2 / Woocommerce 3.2.6 / Emmet Lite theme 1.7.0

  • one
    "Now my site uses a star rating of this kind ... It is not very beautiful, like a star rating (what they are separated)" - I did not understand, why did I answer you the question: ru.stackoverflow.com/a/771159/ 220220 - KAGG Design
  • Changing the concept. Your rule worked fine, but you need to do it through your fingers. - Vlad Yudkin

1 answer 1

Without crutches can not do. I would first conclude the number of likes:

 <?php $product = wc_get_product( $product_id ); $rating_count = $product->get_rating_count(); ?> 

Then I would write functions with execution via AJAX on the principle of getting the current rating and changing towards the like / dislike:

 <?php $rating = $rating_count - 1; // Дизлайк $rating = $rating_count + 1; // Лайк update_post_meta($product_id, '_wc_rating_count', $rating); //update_post_meta($product_id, '_wc_review_count', $rating); ?> 

I lowered a lot of nuances, but the principle should be clear.

  • Well, why crutches. The normal code should look like a solution. - KAGG Design
  • But I'm not sure that _wc_review_count is what you need, not the total number of product reviews. I’ve seen this code for a long time, but it seems to me that it’s done differently there. - KAGG Design
  • True, there is likely _wc_rating_count, but again it’s necessary to test. - noname228