Automattic\WooCommerce\Blocks\Templates

SingleProductTemplateCompatibility::inject_hooks()publicWC 1.0

Inject hooks to rendered content of corresponding blocks.

Метод класса: SingleProductTemplateCompatibility{}

Хуков нет.

Возвращает

Строку.

Использование

$SingleProductTemplateCompatibility = new SingleProductTemplateCompatibility();
$SingleProductTemplateCompatibility->inject_hooks( $block_content, $block );
$block_content(разное) (обязательный)
The rendered block content.
$block(разное) (обязательный)
The parsed block data.

Код SingleProductTemplateCompatibility::inject_hooks() WC 8.7.0

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' )
	);
}