Automattic\WooCommerce\Blocks\BlockTypes

SingleProduct::restore_global_postpublicWC 1.0

Restore the global post variable right before generating the render output for the post title and/or post excerpt blocks.

This is required due to the changes made via the replace_post_for_single_product_inner_block method. It is a temporary fix to ensure these blocks work as expected until Gutenberg versions 15.2 and 15.6 are part of the core of WordPress.

Method of the class: SingleProduct{}

No Hooks.

Returns

Mixed.

Usage

$SingleProduct = new SingleProduct();
$SingleProduct->restore_global_post( $block_content, $parsed_block, $block_instance );
$block_content(string) (required)
The block content.
$parsed_block(array) (required)
The full block, including name and attributes.
$block_instance(WP_Block) (required)
The block instance.

Notes

SingleProduct::restore_global_post() code WC 9.8.5

public function restore_global_post( $block_content, $parsed_block, $block_instance ) {
	if ( isset( $block_instance->context['singleProduct'] ) && $block_instance->context['singleProduct'] ) {
		wp_reset_postdata();
	}

	return $block_content;
}