Automattic\WooCommerce\Blocks\BlockTypes\Reviews

ProductReviewForm::render_starsprivateWC 1.0

Render stars for rating selector.

Method of the class: ProductReviewForm{}

No Hooks.

Returns

null. Nothing (null).

Usage

// private - for code of main (parent) class only
$result = $this->render_stars();

ProductReviewForm::render_stars() code WC 10.3.6

<?php
private function render_stars() {
	ob_start();
	echo '<span class="stars">';
	for ( $i = 1; $i < 6; $i++ ) {
		?>
		<button
			role="radio"
			type="button"
			<?php /* translators: %d is the rating value from 1 to 5 */ ?>
			aria-label='<?php echo esc_attr( sprintf( _n( '%d of 5 star', '%d of 5 stars', $i, 'woocommerce' ), $i ) ); ?>'
			data-wp-on-async--mouseenter="actions.hoverStar"
			data-wp-on-async--mouseleave="actions.leaveStar"
			data-wp-on-async--click="actions.selectStar"
			data-wp-on-async--keydown="actions.changeRatingWithKeyboard"
			data-wp-class--is-hovered="state.isStarHovered"
			data-wp-class--is-selected="state.isStarSelected"
			data-wp-bind--aria-checked="state.isStarSelected"
			<?php echo wp_interactivity_data_wp_context( [ 'starValue' => $i ] ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
		>
			<svg
				width='24'
				height='24'
				viewBox='0 0 24 24'
				aria-hidden="true"
				focusable="false"
			>
				<path d="M12 17.27L18.18 21l-1.64-7.03L22 9.24l-7.19-.61L12 2 9.19 8.63 2 9.24l5.46 4.73L5.82 21z" fill="none" stroke="currentColor" stroke-width="1.5"/>
			</svg>
		</button>
		<?php
	}
	echo '</span>';
	return ob_get_clean();
}