Automattic\WooCommerce\Blocks\Templates

SingleProductTemplateCompatibility::inject_hooks()publicWC 1.0

Inject hooks to rendered content of corresponding blocks.

Method of the class: SingleProductTemplateCompatibility{}

No Hooks.

Return

String.

Usage

$SingleProductTemplateCompatibility = new SingleProductTemplateCompatibility();
$SingleProductTemplateCompatibility->inject_hooks( $block_content, $block );
$block_content(mixed) (required)
The rendered block content.
$block(mixed) (required)
The parsed block data.

SingleProductTemplateCompatibility::inject_hooks() code WC 9.4.2

public function inject_hooks( $block_content, $block ) {
	if ( ! is_product() ) {
		return $block_content;
	}

	$this->remove_default_hooks();

	$block_name = $block['blockName'];

	$block_hooks = array_filter(
		$this->hook_data,
		function ( $hook ) use ( $block_name ) {
			return in_array( $block_name, $hook['block_names'], true );
		}
	);

	$first_or_last_block_content = $this->inject_hook_to_first_and_last_blocks( $block_content, $block, $block_hooks );

	if ( isset( $first_or_last_block_content ) ) {
		return $first_or_last_block_content;
	}

	return sprintf(
		'%1$s%2$s%3$s',
		$this->get_hooks_buffer( $block_hooks, 'before' ),
		$block_content,
		$this->get_hooks_buffer( $block_hooks, 'after' )
	);
}