Automattic\WooCommerce\Admin\API\Reports

DataStore::get_products_by_cat_ids()protectedWC 1.0

Returns an array of products belonging to given categories.

Method of the class: DataStore{}

No Hooks.

Return

Array|stdClass.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_products_by_cat_ids( $categories );
$categories(array) (required)
List of categories IDs.

DataStore::get_products_by_cat_ids() code WC 8.7.0

protected function get_products_by_cat_ids( $categories ) {
	$terms = get_terms(
		array(
			'taxonomy' => 'product_cat',
			'include'  => $categories,
		)
	);

	if ( is_wp_error( $terms ) || empty( $terms ) ) {
		return array();
	}

	$args = array(
		'category' => wc_list_pluck( $terms, 'slug' ),
		'limit'    => -1,
		'return'   => 'ids',
	);
	return wc_get_products( $args );
}