Automattic\WooCommerce\Blocks\BlockTypes
ProductRating::render()
Include and render the block.
Метод класса: ProductRating{}
Хуков нет.
Возвращает
Строку
. Rendered block type output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
По умолчанию: empty array - $content(строка) (обязательный)
- Block content.
По умолчанию: empty string - $block(WP_Block) (обязательный)
- Block instance.
Код ProductRating::render() ProductRating::render WC 7.3.0
protected function render( $attributes, $content, $block ) { if ( ! empty( $content ) ) { parent::register_block_type_assets(); $this->register_chunk_translations( [ $this->block_name ] ); return $content; } $post_id = $block->context['postId']; $product = wc_get_product( $post_id ); add_filter( 'woocommerce_product_get_rating_html', [ $this, 'filter_rating_html' ], 10, 3 ); if ( $product ) { $styles_and_classes = StyleAttributesUtils::get_classes_and_styles_by_attributes( $attributes, array( 'font_size', 'margin', 'text_color' ) ); $text_align_styles_and_classes = StyleAttributesUtils::get_text_align_class_and_style( $attributes ); return sprintf( '<div class="wc-block-components-product-rating wc-block-grid__product-rating %1$s %2$s" style="%3$s"> %4$s </div>', esc_attr( $text_align_styles_and_classes['class'] ?? '' ), esc_attr( $styles_and_classes['classes'] ), esc_attr( $styles_and_classes['styles'] ?? '' ), wc_get_rating_html( $product->get_average_rating() ) ); } }