Automattic\WooCommerce\Blocks\BlockTypes
SavedForLater::register_hooked_block
Auto-inject this block after woocommerce/cart, scoped to the cart page.
Метод класса: SavedForLater{}
Хуков нет.
Возвращает
Массив.
Использование
$SavedForLater = new SavedForLater(); $SavedForLater->register_hooked_block( $hooked_block_types, $relative_position, $anchor_block_type, $context );
- $hooked_block_types(массив) (обязательный)
- Block names hooked at this position.
- $relative_position(строка) (обязательный)
- Position of the insertion point.
- $anchor_block_type(строка) (обязательный)
- Anchor block name.
- $context(массив|\WP_Post|\WP_Block_Template|null) (обязательный)
- Where the block is being embedded.
Код SavedForLater::register_hooked_block() SavedForLater::register hooked block WC 11.0.1
public function register_hooked_block( $hooked_block_types, $relative_position, $anchor_block_type, $context ) {
if ( 'after' !== $relative_position || 'woocommerce/cart' !== $anchor_block_type ) {
return $hooked_block_types;
}
// `wc_get_page_id()` returns -1 when the page option isn't set.
$cart_page_id = (int) wc_get_page_id( 'cart' );
if ( $cart_page_id <= 0 || ! ( $context instanceof \WP_Post ) || (int) $context->ID !== $cart_page_id ) {
return $hooked_block_types;
}
// Don't double-inject if the block is already in the cart page
// content.
if ( has_block( $this->get_full_block_name(), $context ) ) {
return $hooked_block_types;
}
$hooked_block_types[] = $this->get_full_block_name();
return $hooked_block_types;
}