From 5826a9bce0f50cbc37b0b1261f7dbe2dd2ce7819 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 19:56:05 -0300 Subject: [PATCH] Display total of customer reviews and applied to rating template --- includes/wc-template-functions.php | 26 +++++++++++++++++-------- templates/single-product/rating.php | 30 ++++++----------------------- 2 files changed, 24 insertions(+), 32 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index e20c011847a..42c153f652d 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2546,18 +2546,20 @@ function wc_get_stock_html( $product ) { * * @since 3.0.0 * @param float $rating Rating being shown. + * @param int $count Total of ratings. * @return string */ -function wc_get_rating_html( $rating ) { - if ( $rating > 0 ) { +function wc_get_rating_html( $rating, $count = 0 ) { + if ( 0 < $rating ) { /* translators: %s: rating */ $html = '
'; - $html .= wc_get_star_rating_html( $rating ); + $html .= wc_get_star_rating_html( $rating, $count ); $html .= '
'; } else { $html = ''; } - return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating ); + + return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating, $count ); } /** @@ -2565,15 +2567,23 @@ function wc_get_rating_html( $rating ) { * * @since 3.1.0 * @param float $rating Rating being shown. + * @param int $count Total of ratings. * @return string */ -function wc_get_star_rating_html( $rating ) { +function wc_get_star_rating_html( $rating, $count = 0 ) { $html = ''; - /* translators: %s: rating */ - $html .= sprintf( esc_html__( '%s out of 5', 'woocommerce' ), '' . $rating . '' ); + + if ( 0 < $count ) { + /* translators: 1: rating 2: rating count */ + $html .= sprintf( _n( '%1$s out of 5 based on %2$s customer rating', '%1$s out of 5 based on %2$s customer ratings', $count, 'woocommerce' ), '' . esc_html( $rating ) . '', '' . esc_html( $count ) . '' ); + } else { + /* translators: %s: rating */ + $html .= sprintf( esc_html__( '%s out of 5', 'woocommerce' ), '' . esc_html( $rating ) . '' ); + } + $html .= ''; - return apply_filters( 'woocommerce_get_star_rating_html', $html ); + return apply_filters( 'woocommerce_get_star_rating_html', $html, $rating, $count ); } /** diff --git a/templates/single-product/rating.php b/templates/single-product/rating.php index 446b9d2b76a..df55e56b107 100644 --- a/templates/single-product/rating.php +++ b/templates/single-product/rating.php @@ -10,10 +10,10 @@ * happen. When this occurs the version of the template file will be bumped and * the readme will list any important changes. * - * @see https://docs.woocommerce.com/document/template-structure/ - * @author WooThemes - * @package WooCommerce/Templates - * @version 2.3.2 + * @see https://docs.woocommerce.com/document/template-structure/ + * @author WooThemes + * @package WooCommerce/Templates + * @version 3.1.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -22,7 +22,7 @@ if ( ! defined( 'ABSPATH' ) ) { global $product; -if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) { +if ( 'no' === get_option( 'woocommerce_enable_review_rating' ) ) { return; } @@ -33,25 +33,7 @@ $average = $product->get_average_rating(); if ( $rating_count > 0 ) : ?>
-
- - ' . esc_html( $average ) . '', - '5' - ); - ?> - ' . esc_html( $rating_count ) . '' - ); - ?> - -
+ (' . esc_html( $review_count ) . '' ); ?>)