Automattic\WooCommerce\Internal\StockNotifications\Utilities

EligibilityService::get_target_product_ids │ public │ WC 10.2.0

Get the product IDs that need to be checked for stock notifications.

For simple products, this returns just the product ID. For variable products that manage stock, it also returns the IDs of the variations that share the parent's stock. Variations of a parent that does not manage stock keep their own stock status.

This is used in two key scenarios:

  1. Checking if a product has any active notifications
  2. Determining which notifications need to be sent during a stock broadcast

Method of the class: EligibilityService{}

No Hooks.

Returns

array<int>. Array of product IDs to check for notifications.

Usage

$EligibilityService = new EligibilityService();
$EligibilityService->get_target_product_ids( $product ): array;
$product(WC_Product) (required)
The product to check.

Changelog

Since 10.2.0 Introduced.

EligibilityService::get_target_product_ids() code WC 11.3.0

public function get_target_product_ids( WC_Product $product ): array {
	$lookup_ids = array( $product->get_id() );
	if ( $product->is_type( ProductType::VARIABLE ) && $product->get_manage_stock() ) {
		$children_ids = $this->stock_management_helper->get_managed_variations( $product );
		$lookup_ids   = array_merge( $lookup_ids, $children_ids );
	}

	return $lookup_ids;
}