<?php 
?>

          <div class="emtiaz">
                
                        <div class="emtiaz-2">
                            <!-- Averate Rating -->
                            <div class="emtiaz-3">
						
							                            <div class="emtiaz-33">
	<div class="emtiaz-title">
							متوسط امتیاز ها
							</div>
                                    <div class="emtiaz-number"><?php echo esc_attr($average); ?></div>
                              <div class="emtiaz-star">
							                                          <?php do_action( 'woocommerce_after_shop_loop_item_title' ); ?>

							  </div>
                                   
                            </div></div>

                            <!-- Detailed Ratings-->
                            <?php
                            // WP_Comment_Query arguments
                            $args = array (
                                'status'         => 'approve',
                                'type'           => 'review',
                                'post_id'        => get_the_id(),
                            );

                            // The Comment Query
                            $woo_reviews = new WP_Comment_Query;
                            $comments = $woo_reviews->query( $args );

                            $rate1 = $rate2 = $rate3 = $rate4 = $rate5 = 0;
                            // The Comment Loop
                            if ( $comments ) {
                                foreach ( $comments as $comment ) {
                                    $rate = get_comment_meta($comment->comment_ID, 'rating', true);
                                    switch($rate) {
                                        case 1:
                                            $rate1++;
                                            break;
                                        case 2:
                                            $rate2++;
                                            break;
                                        case 3:
                                            $rate3++;
                                            break;
                                        case 4:
                                            $rate4++;
                                            break;
                                        case 5:
                                            $rate5++;
                                            break;
                                    } // switch
                                }
                            }
                            $rates = array('5'=>$rate5,'4'=>$rate4,'3'=>$rate3,'2'=>$rate2,'1'=>$rate1);
                            ?>
                            <div class="emtiaz-4">
						
                                <div class="emtiaz-5">
	                                <?php foreach($rates as $key => $rate): ?>
		                               
                                        <div class="emtiaz-6">
										                                            <span class="number"><?php echo esc_attr($key.' '.__('ستاره', 'studiare')); ?></span>

                                            <div class="bars">
                                                <div class="barsf" style="width:<?php echo esc_attr($fill_value); ?>%"></div>
                                            </div>
                                            <span class="shomaresh"><?php echo esc_attr($rate); ?></span>
                                        </div>
	                                <?php endforeach; ?>
                                </div>
                            </div>
                        </div>

            
                </div>	