Automattic\WooCommerce\Blocks\BlockTypes

SavedForLater::register_hooked_blockpublicWC 1.0

Auto-inject this block after woocommerce/cart, scoped to the cart page.

Method of the class: SavedForLater{}

No Hooks.

Returns

Array.

Usage

$SavedForLater = new SavedForLater();
$SavedForLater->register_hooked_block( $hooked_block_types, $relative_position, $anchor_block_type, $context );
$hooked_block_types(array) (required)
Block names hooked at this position.
$relative_position(string) (required)
Position of the insertion point.
$anchor_block_type(string) (required)
Anchor block name.
$context(array|\WP_Post|\WP_Block_Template|null) (required)
Where the block is being embedded.

SavedForLater::register_hooked_block() code WC 10.9.4

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