Automattic\WooCommerce\Blocks\BlockTypes

SingleProduct::update_context()publicWC 1.0

Update the context by injecting the correct post data for each one of the Single Product inner blocks.

Method of the class: SingleProduct{}

No Hooks.

Return

Array. Updated block context.

Usage

$SingleProduct = new SingleProduct();
$SingleProduct->update_context( $context, $block, $parent_block );
$context(array) (required)
Block context.
$block(array) (required)
Block attributes.
$parent_block(WP_Block) (required)
Block instance.

SingleProduct::update_context() code WC 9.4.2

public function update_context( $context, $block, $parent_block ) {
	if ( 'woocommerce/single-product' === $block['blockName']
		&& isset( $block['attrs']['productId'] ) ) {
			$this->product_id = $block['attrs']['productId'];

			$this->single_product_inner_blocks_names = array_reverse(
				$this->extract_single_product_inner_block_names( $block )
			);
	}

	$this->replace_post_for_single_product_inner_block( $block, $context );

	return $context;
}