From a049835c050b842d5052cb735fb1230ae027e850 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 19:32:25 -0300 Subject: [PATCH 01/15] Introduced new wc_get_star_rating_html() function --- includes/wc-template-functions.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 5855238a17a..e454c15bc1f 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2550,13 +2550,26 @@ function wc_get_stock_html( $product ) { */ function wc_get_rating_html( $rating ) { if ( $rating > 0 ) { - $rating_html = '
'; - $rating_html .= '' . $rating . ' ' . esc_html__( 'out of 5', 'woocommerce' ) . ''; - $rating_html .= '
'; + $html = '
'; + $html .= wc_get_star_rating_html(); + $html .= '
'; } else { - $rating_html = ''; + $html = ''; } - return apply_filters( 'woocommerce_product_get_rating_html', $rating_html, $rating ); + return apply_filters( 'woocommerce_product_get_rating_html', $html, $rating ); +} + +/** + * Get HTML for star rating. + * + * @since 3.1.0 + * @param float $rating Rating being shown. + * @return string + */ +function wc_get_star_rating_html( $rating ) { + $html = '' . $rating . ' ' . esc_html__( 'out of 5', 'woocommerce' ) . ''; + + return apply_filters( 'woocommerce_get_star_rating_html', $html ); } /** From 915a4c7f59724b3c56f4dccbf9d58ab51234aff4 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 19:33:39 -0300 Subject: [PATCH 02/15] Applied wc_get_rating_html() to review rating template --- templates/single-product/review-rating.php | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/templates/single-product/review-rating.php b/templates/single-product/review-rating.php index d3bafe5d01a..63a3d5d8dce 100644 --- a/templates/single-product/review-rating.php +++ b/templates/single-product/review-rating.php @@ -13,7 +13,7 @@ * @see https://docs.woocommerce.com/document/template-structure/ * @author WooThemes * @package WooCommerce/Templates - * @version 3.0.0 + * @version 3.1.0 */ if ( ! defined( 'ABSPATH' ) ) { @@ -23,13 +23,6 @@ if ( ! defined( 'ABSPATH' ) ) { global $comment; $rating = intval( get_comment_meta( $comment->comment_ID, 'rating', true ) ); -if ( $rating && get_option( 'woocommerce_enable_review_rating' ) === 'yes' ) { ?> - -
- ' . $rating . '' ); - ?> -
- - Date: Fri, 28 Apr 2017 19:36:43 -0300 Subject: [PATCH 03/15] Better i18n support --- includes/wc-template-functions.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index e454c15bc1f..60a711b4637 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2550,6 +2550,7 @@ function wc_get_stock_html( $product ) { */ function wc_get_rating_html( $rating ) { if ( $rating > 0 ) { + /* translators: %s: rating */ $html = '
'; $html .= wc_get_star_rating_html(); $html .= '
'; @@ -2567,7 +2568,10 @@ function wc_get_rating_html( $rating ) { * @return string */ function wc_get_star_rating_html( $rating ) { - $html = '' . $rating . ' ' . esc_html__( 'out of 5', 'woocommerce' ) . ''; + $html = ''; + /* translators: %s: rating */ + $html .= sprintf( esc_html__( '%s out of 5', 'woocommerce' ), '' . $rating . '' ); + $html .= ''; return apply_filters( 'woocommerce_get_star_rating_html', $html ); } From 685b999357058c313b9b99246d699c5841b94680 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 19:41:11 -0300 Subject: [PATCH 04/15] Fixed missing variable --- includes/wc-template-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 60a711b4637..e20c011847a 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2552,7 +2552,7 @@ function wc_get_rating_html( $rating ) { if ( $rating > 0 ) { /* translators: %s: rating */ $html = '
'; - $html .= wc_get_star_rating_html(); + $html .= wc_get_star_rating_html( $rating ); $html .= '
'; } else { $html = ''; From 5826a9bce0f50cbc37b0b1261f7dbe2dd2ce7819 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 19:56:05 -0300 Subject: [PATCH 05/15] 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 ) . '' ); ?>)
From 1d65c9d8b7f99f0d7321cf453b8159340267fe75 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 19:59:50 -0300 Subject: [PATCH 06/15] Better screen reader support --- includes/wc-template-functions.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 42c153f652d..dc2474a97e3 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2552,7 +2552,7 @@ function wc_get_stock_html( $product ) { function wc_get_rating_html( $rating, $count = 0 ) { if ( 0 < $rating ) { /* translators: %s: rating */ - $html = '
'; + $html = '
'; $html .= wc_get_star_rating_html( $rating, $count ); $html .= '
'; } else { @@ -2575,10 +2575,10 @@ function wc_get_star_rating_html( $rating, $count = 0 ) { 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 ) . '' ); + $html .= sprintf( _n( 'Rated %1$s out of 5 based on %2$s customer rating', 'Rated %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 .= sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), '' . esc_html( $rating ) . '' ); } $html .= ''; From 26a6dfa803013b2b7305e843c946beb22779471c Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 20:01:01 -0300 Subject: [PATCH 07/15] Applied wc_get_star_rating_html() to rating filter widget --- includes/widgets/class-wc-widget-rating-filter.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/widgets/class-wc-widget-rating-filter.php b/includes/widgets/class-wc-widget-rating-filter.php index 79f86b2f166..5f2c8b3bfac 100644 --- a/includes/widgets/class-wc-widget-rating-filter.php +++ b/includes/widgets/class-wc-widget-rating-filter.php @@ -184,9 +184,9 @@ class WC_Widget_Rating_Filter extends WC_Widget { echo ''; - echo ' - ' . sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), $rating ) . ' - (' . esc_html( $count ) . ')'; + echo ''; + echo wc_get_star_rating_html( $rating ); + echo ' (' . esc_html( $count ) . ')'; echo ''; From ad09564ff32f5fc34b3797276de021a51b2ca2ae Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Fri, 28 Apr 2017 20:08:37 -0300 Subject: [PATCH 08/15] Removed extra comment --- includes/wc-template-functions.php | 1 - 1 file changed, 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index dc2474a97e3..076ce080af1 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2551,7 +2551,6 @@ function wc_get_stock_html( $product ) { */ function wc_get_rating_html( $rating, $count = 0 ) { if ( 0 < $rating ) { - /* translators: %s: rating */ $html = '
'; $html .= wc_get_star_rating_html( $rating, $count ); $html .= '
'; From ed5877f395bd1662ddb3bdd2a2ac8708dc0b4fb0 Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Tue, 2 May 2017 16:48:00 -0300 Subject: [PATCH 09/15] Improve docblocks --- includes/wc-template-functions.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 076ce080af1..ea057ee9113 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -2546,7 +2546,7 @@ function wc_get_stock_html( $product ) { * * @since 3.0.0 * @param float $rating Rating being shown. - * @param int $count Total of ratings. + * @param int $count Total number of ratings. * @return string */ function wc_get_rating_html( $rating, $count = 0 ) { @@ -2566,7 +2566,7 @@ function wc_get_rating_html( $rating, $count = 0 ) { * * @since 3.1.0 * @param float $rating Rating being shown. - * @param int $count Total of ratings. + * @param int $count Total number of ratings. * @return string */ function wc_get_star_rating_html( $rating, $count = 0 ) { From 1753406dc021d59c82329bfedef1f6d8394ac8df Mon Sep 17 00:00:00 2001 From: Claudio Sanches Date: Thu, 4 May 2017 18:54:44 -0300 Subject: [PATCH 10/15] Fixed warning when no customer country is defined. Fixes #14850 --- includes/wc-template-functions.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/wc-template-functions.php b/includes/wc-template-functions.php index 5855238a17a..72652f12ee8 100644 --- a/includes/wc-template-functions.php +++ b/includes/wc-template-functions.php @@ -1981,7 +1981,7 @@ if ( ! function_exists( 'woocommerce_form_field' ) ) { $field .= ''; - } elseif ( is_array( $states ) ) { + } elseif ( ! is_null( $current_cc ) && is_array( $states ) ) { $field .= '