Automattic\WooCommerce\Blocks\Templates

SingleProductTemplate::render_block_templatepublicWC 1.0

Run template-specific logic when the query matches this template.

Method of the class: SingleProductTemplate{}

No Hooks.

Returns

null. Nothing (null).

Usage

$SingleProductTemplate = new SingleProductTemplate();
$SingleProductTemplate->render_block_template();

SingleProductTemplate::render_block_template() code WC 11.0.1

public function render_block_template() {
	if ( ! is_embed() && is_singular( 'product' ) ) {
		global $post;

		$compatibility_layer = new SingleProductTemplateCompatibility();
		$compatibility_layer->init();

		$product = wc_get_product( $post->ID );
		if ( $product ) {
			$consent = 'I acknowledge that using experimental APIs means my theme or plugin will inevitably break in the next version of WooCommerce';

			// Load the product data into the products store so derived
			// state closures can resolve it during server-side rendering.
			ProductsStore::load_product( $consent, $product->get_id() );

			// Set the current product context. The derived state
			// closures (mainProductInContext, productVariationInContext, productInContext)
			// are registered by ProductsStore::register_state().
			wp_interactivity_state(
				'woocommerce/products',
				array(
					'productId'   => $product->get_id(),
					'variationId' => null,
				)
			);
		}
	}
}