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

Product_Collection::get_related_product_idsprivateWC 1.0

Get related product IDs.

Method of the class: Product_Collection{}

No Hooks.

Returns

Array. Array of related product IDs.

Usage

// private - for code of main (parent) class only
$result = $this->get_related_product_ids( $parsed_block ): array;
$parsed_block(array) (required)
Parsed block data.

Product_Collection::get_related_product_ids() code WC 10.5.0

private function get_related_product_ids( array $parsed_block ): array {
	$product_references = $this->get_product_references_for_collection( $parsed_block );

	if ( empty( $product_references ) ) {
		return array( -1 ); // Return -1 to ensure no products are found.
	}

	// For related products, we only use the first product reference.
	$product_reference = $product_references[0];

	if ( empty( $product_reference ) ) {
		return array( -1 );
	}

	// Get related products using WooCommerce's built-in function.
	$related_ids = wc_get_related_products( $product_reference, 100 );
	return ! empty( $related_ids ) ? $related_ids : array( -1 );
}