Automattic\WooCommerce\Blocks\BlockTypes\Reviews

ProductReviewRating::renderprotectedWC 1.0

Render the block.

Method of the class: ProductReviewRating{}

No Hooks.

Returns

String. Rendered block content.

Usage

// protected - for code of main (parent) or child class
$result = $this->render( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block) (required)
Block instance.

ProductReviewRating::render() code WC 10.7.0

protected function render( $attributes, $content, $block ) {
	if ( ! isset( $block->context['commentId'] ) ) {
		return '';
	}

	$rating = intval( get_comment_meta( $block->context['commentId'], 'rating', true ) );

	$html = '';

	if ( 0 < $rating ) {
		// translators: %s: Rating.
		$label = sprintf( __( 'Rated %s out of 5', 'woocommerce' ), $rating );
		$html  = sprintf(
			'<div class="wc-block-product-review-rating__container">
				<div class="wc-block-product-review-rating__stars" role="img" aria-label="%1$s">
					%2$s
				</div>
			</div>
			',
			esc_attr( $label ),
			wc_get_star_rating_html( $rating )
		);
	}

	return sprintf(
		'<div %1$s>
			%2$s
		</div>',
		get_block_wrapper_attributes(),
		$html
	);
}