Automattic\WooCommerce\Blocks\BlockTypes\Reviews
ProductReviewRating::render
Render the block.
Метод класса: ProductReviewRating{}
Хуков нет.
Возвращает
Строку. Rendered block content.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код ProductReviewRating::render() ProductReviewRating::render WC 11.0.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
);
}