Easy Testimonials Aggregate Rating Filter Example

  1. /* Gold Plugins Aggregate Rating Edit */
  2. function modify_easy_t_aggregate_rating( $output, $count_query ) {
  3. //Valutato 4.67/5 in base a 3 recensioni
  4. //calculate average review value
  5. $total_rating = 0;
  6. $total_rated_testimonials = 0;//only want to divide by the number of testimonials with actual ratings
  7. $item_reviewed = get_option('easy_t_global_item_reviewed','');
  8. foreach ($count_query->posts as $testimonial){
  9. $testimonial_rating = get_post_meta($testimonial->ID, '_ikcf_rating', true);
  10. if(intval($testimonial_rating) > 0){
  11. $total_rated_testimonials ++;
  12. $total_rating += $testimonial_rating;
  13. }
  14. }
  15.  
  16. $average_rating = $total_rating / $total_rated_testimonials;
  17. $output = '
  18. <div class="easy_t_aggregate_rating_wrapper" itemscope itemtype="http://schema.org/Product">
  19. <span class="easy_t_aggregate_rating_item" itemprop="name">' . $item_reviewed . '</span>
  20. <div class="easy_t_aggregate_rating" itemprop="aggregateRating" itemscope itemtype="http://schema.org/AggregateRating">Valutato <span class="easy_t_aggregate_rating_top_count" itemprop="ratingValue">' . round($average_rating, 2) . '</span>/5 in base a <span itemprop="reviewCount" class="easy_t_aggregate_rating_review_count" >' . $total_rated_testimonials . '</span> recensioni</div>
  21. </div>
  22. ';
  23. return $output;
  24. }
  25. add_filter( 'easy_t_aggregate_rating', 'modify_easy_t_aggregate_rating', 10, 2 );