Automattic\WooCommerce\Internal\OrderReviews

StarRating::renderpublic staticWC 10.8.0

Render the rating control. Returns the HTML; does not echo.

Required keys in $args:

  • name (string): form field name (one per item).
  • id_prefix (string): prefix used to build unique radio ids.
  • label_id (string): id of the existing label element that describes
the group via `aria-labelledby`.

Optional:

  • selected (int): pre-selected value 0-5; pass 0 (the default)
    for no pre-selection. Values outside 0-5 are treated as no selection.

Method of the class: StarRating{}

No Hooks.

Returns

String.

Usage

$result = StarRating::render( $args ): string;
$args(array) (required)
Render arguments. See description for required and optional keys.

Changelog

Since 10.8.0 Introduced.

StarRating::render() code WC 10.9.1

public static function render( array $args ): string {
	$name      = (string) ( $args['name'] ?? '' );
	$id_prefix = (string) ( $args['id_prefix'] ?? '' );
	$label_id  = (string) ( $args['label_id'] ?? '' );

	if ( '' === $name || '' === $id_prefix || '' === $label_id ) {
		return '';
	}

	$selected = (int) ( $args['selected'] ?? 0 );
	if ( $selected < 0 || $selected > 5 ) {
		$selected = 0;
	}

	ob_start();
	wc_get_template(
		'order/star-rating.php',
		array(
			'name'      => $name,
			'id_prefix' => $id_prefix,
			'label_id'  => $label_id,
			'selected'  => $selected,
			'labels'    => self::get_labels(),
		)
	);
	return (string) ob_get_clean();
}