Automattic\WooCommerce\Blocks\Templates

SingleProductTemplateCompatibility::inject_hook_to_first_and_last_blocks()privateWC 1.0

Inject custom hooks to the first and last blocks. Since that there is a custom logic for the first and last block, we have to inject the hooks manually. The first block supports the following hooks: woocommerce_before_single_product

The last block supports the following hooks: woocommerce_after_single_product

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

Хуков нет.

Возвращает

Строку.

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

// private - только в коде основоного (родительского) класса
$result = $this->inject_hook_to_first_and_last_blocks( $block_content, $block, $block_hooks );
$block_content(разное) (обязательный)
The rendered block content.
$block(разное) (обязательный)
The parsed block data.
$block_hooks(массив) (обязательный)
The hooks that should be injected to the block.

Код SingleProductTemplateCompatibility::inject_hook_to_first_and_last_blocks() WC 8.7.0

private function inject_hook_to_first_and_last_blocks( $block_content, $block, $block_hooks ) {
	$first_block_hook = array(
		'before' => array(
			'woocommerce_before_main_content'   => $this->hook_data['woocommerce_before_main_content'],
			'woocommerce_before_single_product' => $this->hook_data['woocommerce_before_single_product'],
		),
		'after'  => array(),
	);

	$last_block_hook = array(
		'before' => array(),
		'after'  => array(
			'woocommerce_after_single_product' => $this->hook_data['woocommerce_after_single_product'],
			'woocommerce_after_main_content'   => $this->hook_data['woocommerce_after_main_content'],
			'woocommerce_sidebar'              => $this->hook_data['woocommerce_sidebar'],
		),
	);

	if ( isset( $block['attrs'][ self::IS_FIRST_BLOCK ] ) && isset( $block['attrs'][ self::IS_LAST_BLOCK ] ) ) {
		return sprintf(
			'%1$s%2$s',
			$this->inject_hooks_after_the_wrapper(
				$block_content,
				array_merge(
					$first_block_hook['before'],
					$block_hooks,
					$last_block_hook['before']
				)
			),
			$this->get_hooks_buffer(
				array_merge(
					$first_block_hook['after'],
					$block_hooks,
					$last_block_hook['after']
				),
				'after'
			)
		);
	}

	if ( isset( $block['attrs'][ self::IS_FIRST_BLOCK ] ) ) {
		return sprintf(
			'%1$s%2$s',
			$this->inject_hooks_after_the_wrapper(
				$block_content,
				array_merge(
					$first_block_hook['before'],
					$block_hooks
				)
			),
			$this->get_hooks_buffer(
				array_merge(
					$first_block_hook['after'],
					$block_hooks
				),
				'after'
			)
		);
	}

	if ( isset( $block['attrs'][ self::IS_LAST_BLOCK ] ) ) {
		return sprintf(
			'%1$s%2$s%3$s',
			$this->get_hooks_buffer(
				array_merge(
					$last_block_hook['before'],
					$block_hooks
				),
				'before'
			),
			$block_content,
			$this->get_hooks_buffer(
				array_merge(
					$block_hooks,
					$last_block_hook['after']
				),
				'after'
			)
		);
	}
}