Automattic\WooCommerce\EmailEditor\Integrations\WooCommerce\Renderer\Blocks

Product_Collection::get_cart_contents_product_ids │ private │ WC 1.0

Get cart contents product IDs for email rendering.

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

Хуков нет.

Возвращает

array. Array of cart product IDs or sample products for preview.

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

// private - только в коде основоного (родительского) класса
$result = $this->get_cart_contents_product_ids( $parsed_block, $rendering_context ): array;
$parsed_block(массив) (обязательный)
Parsed block data.
$rendering_context(Rendering_Context) (обязательный)
Rendering context.

Код Product_Collection::get_cart_contents_product_ids() WC 11.2.2

private function get_cart_contents_product_ids( array $parsed_block, Rendering_Context $rendering_context ): array {
	// Try to get cart product IDs from the user's cart using user ID or email.
	$cart_product_ids = $this->get_user_cart_product_ids_from_context( $rendering_context );

	if ( ! empty( $cart_product_ids ) ) {
		return $cart_product_ids;
	}

	// For preview emails, show sample products so users can see what the email will look like.
	if ( $rendering_context->get( 'is_user_preview', false ) ) {
		return $this->get_sample_product_ids_for_preview();
	}

	// For real emails with empty cart, return -1 to ensure no products are shown.
	return array( -1 );
}