Automattic\WooCommerce\Admin\API\Reports

DataStore::get_included_products_array()protectedWC 1.0

Returns an array of ids of allowed products, based on query arguments from the user.

Method of the class: DataStore{}

No Hooks.

Return

Array.

Usage

// protected - for code of main (parent) or child class
$result = $this->get_included_products_array( $query_args );
$query_args(array) (required)
Parameters supplied by the user.

DataStore::get_included_products_array() code WC 8.7.0

protected function get_included_products_array( $query_args ) {
	$included_products = array();
	$operator          = $this->get_match_operator( $query_args );

	if ( isset( $query_args['category_includes'] ) && is_array( $query_args['category_includes'] ) && count( $query_args['category_includes'] ) > 0 ) {
		$included_products = $this->get_products_by_cat_ids( $query_args['category_includes'] );

		// If no products were found in the specified categories, we will force an empty set
		// by matching a product ID of -1, unless the filters are OR/any and products are specified.
		if ( empty( $included_products ) ) {
			$included_products = array( '-1' );
		}
	}

	if ( isset( $query_args['product_includes'] ) && is_array( $query_args['product_includes'] ) && count( $query_args['product_includes'] ) > 0 ) {
		if ( count( $included_products ) > 0 ) {
			if ( 'AND' === $operator ) {
				// AND results in an intersection between products from selected categories and manually included products.
				$included_products = array_intersect( $included_products, $query_args['product_includes'] );
			} elseif ( 'OR' === $operator ) {
				// OR results in a union of products from selected categories and manually included products.
				$included_products = array_merge( $included_products, $query_args['product_includes'] );
			}
		} else {
			$included_products = $query_args['product_includes'];
		}
	}

	return $included_products;
}