Automattic\WooCommerce\Admin\API\Reports
DataStore::get_products_by_cat_ids()
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() 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 ); }