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

Product_Collection::get_cart_contents_product_idsprivateWC 1.0

Get cart contents product IDs for email rendering.

Method of the class: Product_Collection{}

No Hooks.

Returns

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

Usage

// private - for code of main (parent) class only
$result = $this->get_cart_contents_product_ids( $parsed_block, $rendering_context ): array;
$parsed_block(array) (required)
Parsed block data.
$rendering_context(Rendering_Context) (required)
Rendering context.

Product_Collection::get_cart_contents_product_ids() code WC 10.5.0

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