wc_get_star_rating_html( float $rating, int $count )
Get HTML for star rating.
Description Description
Parameters Parameters
- $rating
-
(Required) Rating being shown.
- $count
-
(Required) Total number of ratings.
Return Return
(string)
Source Source
File: includes/wc-template-functions.php
function wc_get_star_rating_html( $rating, $count = 0 ) {
$html = '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%">';
if ( 0 < $count ) {
/* translators: 1: rating 2: rating 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' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>', '<span class="rating">' . esc_html( $count ) . '</span>' );
} else {
/* translators: %s: rating */
$html .= sprintf( esc_html__( 'Rated %s out of 5', 'woocommerce' ), '<strong class="rating">' . esc_html( $rating ) . '</strong>' );
}
$html .= '</span>';
return apply_filters( 'woocommerce_get_star_rating_html', $html, $rating, $count );
}
Changelog Changelog
| Version | Description |
|---|---|
| 3.1.0 | Introduced. |