Display total of customer reviews and applied to rating template

This commit is contained in:
Claudio Sanches 2017-04-28 19:56:05 -03:00
parent 685b999357
commit 5826a9bce0
2 changed files with 24 additions and 32 deletions

View File

@ -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 = '<div class="star-rating" title="' . sprintf( esc_attr__( 'Rated %s out of 5', 'woocommerce' ), $rating ) . '">';
$html .= wc_get_star_rating_html( $rating );
$html .= wc_get_star_rating_html( $rating, $count );
$html .= '</div>';
} 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 = '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%">';
/* translators: %s: rating */
$html .= sprintf( esc_html__( '%s out of 5', 'woocommerce' ), '<strong class="rating">' . $rating . '</strong>' );
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' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>', '<span class="rating">' . esc_html( $count ) . '</span>' );
} else {
/* translators: %s: rating */
$html .= sprintf( esc_html__( '%s out of 5', 'woocommerce' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>' );
}
$html .= '</span>';
return apply_filters( 'woocommerce_get_star_rating_html', $html );
return apply_filters( 'woocommerce_get_star_rating_html', $html, $rating, $count );
}
/**

View File

@ -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 ) : ?>
<div class="woocommerce-product-rating">
<div class="star-rating">
<span style="width:<?php echo ( ( $average / 5 ) * 100 ); ?>%">
<?php
/* translators: 1: average rating 2: max rating (i.e. 5) */
printf(
__( '%1$s out of %2$s', 'woocommerce' ),
'<strong class="rating">' . esc_html( $average ) . '</strong>',
'<span>5</span>'
);
?>
<?php
/* translators: %s: rating count */
printf(
_n( 'based on %s customer rating', 'based on %s customer ratings', $rating_count, 'woocommerce' ),
'<span class="rating">' . esc_html( $rating_count ) . '</span>'
);
?>
</span>
</div>
<?php echo wc_get_rating_html( $average, $rating_count ); ?>
<?php if ( comments_open() ) : ?><a href="#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s customer review', '%s customer reviews', $review_count, 'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>
</div>