wc_get_rating_html

Get HTML for ratings.

Description

(string) wc_get_rating_html( (float) $rating ); 

Returns (string)

Parameters (1)

0. $rating (float)
Rating being shown.

Usage

  1. if ( !function_exists( 'wc_get_rating_html' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'woocommerce/includes/wc-template-functions.php'; 
  3.  
  4. // Rating being shown. 
  5. $rating = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = wc_get_rating_html($rating); 
  9.  

Defined (1)

The function is defined in the following location(s).

/includes/wc-template-functions.php  
  1. function wc_get_rating_html( $rating ) { 
  2. if ( $rating > 0 ) { 
  3. $rating_html = '<div class="star-rating" title="' . sprintf( esc_attr__( 'Rated %s out of 5', woocommerce ), $rating ) . '">'; 
  4. $rating_html .= '<span style="width:' . ( ( $rating / 5 ) * 100 ) . '%"><strong class="rating">' . $rating . '</strong> ' . esc_html__( 'out of 5', woocommerce ) . '</span>'; 
  5. $rating_html .= '</div>'; 
  6. } else { 
  7. $rating_html = ''; 
  8. return apply_filters( 'woocommerce_product_get_rating_html', $rating_html, $rating );