Automattic\WooCommerce\Blocks\BlockTypes\Reviews
ProductReviews::render_legacy_block
Previously, the Product Reviews block was a standalone block. It doesn't have any inner blocks and it rendered the tabs directly like the classic template. When upgrading, we want the existing stores using the block to continue working as before, so we moved the logic the legacy render method here.
Метод класса: ProductReviews{}
Хуков нет.
Возвращает
string. Rendered block output.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->render_legacy_block( $attributes, $content, $block );
- $attributes(массив) (обязательный)
- Block attributes.
- $content(строка) (обязательный)
- Block content.
- $block(WP_Block) (обязательный)
- Block instance.
Код ProductReviews::render_legacy_block() ProductReviews::render legacy block WC 11.2.1
protected function render_legacy_block( $attributes, $content, $block ) {
if ( ! is_singular( 'product' ) ) {
return $content;
}
ob_start();
rewind_posts();
while ( have_posts() ) {
the_post();
comments_template();
}
$reviews = ob_get_clean();
return sprintf(
'<div %1$s>
%2$s
</div>',
get_block_wrapper_attributes( array( 'class' => 'wp-block-woocommerce-product-reviews' ) ),
$reviews
);
}