product-rating.php
58 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Single Product Rating |
| 4 | * |
| 5 | * This template can be overridden by copying it to yourtheme/woocommerce/single-product/rating.php. |
| 6 | * |
| 7 | * HOWEVER, on occasion WooCommerce will need to update template files and you |
| 8 | * (the theme developer) will need to copy the new files to your theme to |
| 9 | * maintain compatibility. We try to do this as little as possible, but it does |
| 10 | * happen. When this occurs the version of the template file will be bumped and |
| 11 | * the readme will list any important changes. |
| 12 | * |
| 13 | * @see https://docs.woocommerce.com/document/template-structure/ |
| 14 | * @author WooThemes |
| 15 | * @package WooCommerce/Templates |
| 16 | * @version 2.3.2 |
| 17 | */ |
| 18 | |
| 19 | if ( ! defined( 'ABSPATH' ) ) { |
| 20 | exit; // Exit if accessed directly |
| 21 | } |
| 22 | |
| 23 | global $product; |
| 24 | |
| 25 | if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { |
| 26 | return; |
| 27 | } |
| 28 | |
| 29 | $rating_count = $product->get_rating_count(); |
| 30 | $review_count = $product->get_review_count(); |
| 31 | $average = $product->get_average_rating(); |
| 32 | |
| 33 | if ( $rating_count > 0 ) : ?> |
| 34 | |
| 35 | <div class="woocommerce-product-rating"> |
| 36 | <div class="aux-rating-box aux-star-rating"> |
| 37 | <span style="width:<?php echo esc_attr( ( $average / 5 ) * 100 ); ?>%"> |
| 38 | <?php |
| 39 | /* translators: 1: average rating 2: max rating (i.e. 5) */ |
| 40 | printf( |
| 41 | __( '%1$s out of %2$s', 'auxin-elements' ), |
| 42 | '<strong class="rating">' . esc_html( $average ) . '</strong>', |
| 43 | '<span>5</span>' |
| 44 | ); |
| 45 | ?> |
| 46 | <?php |
| 47 | /* translators: %s: rating count */ |
| 48 | printf( |
| 49 | _n( 'based on %s customer rating', 'based on %s customer ratings', $rating_count, 'auxin-elements' ), |
| 50 | '<span class="rating">' . esc_html( $rating_count ) . '</span>' |
| 51 | ); |
| 52 | ?> |
| 53 | </span> |
| 54 | </div> |
| 55 | </div> |
| 56 | |
| 57 | <?php endif; ?> |
| 58 |