Automattic\WooCommerce\Blocks\BlockTypes\Reviews

ProductReviews::render_legacy_blockprotectedWC 1.0

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.

Method of the class: ProductReviews{}

No Hooks.

Returns

String. Rendered block output.

Usage

// protected - for code of main (parent) or child class
$result = $this->render_legacy_block( $attributes, $content, $block );
$attributes(array) (required)
Block attributes.
$content(string) (required)
Block content.
$block(WP_Block) (required)
Block instance.

ProductReviews::render_legacy_block() code WC 10.6.2

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 class="wp-block-woocommerce-product-reviews %1$s">
			%2$s
		</div>',
		StyleAttributesUtils::get_classes_by_attributes( $attributes, array( 'extra_classes' ) ),
		$reviews
	);
}