Automattic\WooCommerce\Blocks\BlockTypes

AbstractProductGrid::get_rating_html()protectedWC 1.0

Render the rating icons.

Method of the class: AbstractProductGrid{}

No Hooks.

Return

String. Rendered product output.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_rating_html( $product );
$product(WC_Product) (required)
Product.

AbstractProductGrid::get_rating_html() code WC 9.4.2

protected function get_rating_html( $product ) {
	if ( empty( $this->attributes['contentVisibility']['rating'] ) ) {
		return '';
	}
	$rating_count = $product->get_rating_count();
	$average      = $product->get_average_rating();

	if ( $rating_count > 0 ) {
		return sprintf(
			'<div class="wc-block-grid__product-rating">%s</div>',
			wc_get_rating_html( $average, $rating_count ) // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
		);
	}
	return '';
}