WordPress at a glance
function is not described

Automattic\WooCommerce\Admin\API\Reports\Variations\Stats

DataStore::update_sql_query_params() protected WC 1.0

Updates the database query with parameters used for Products Stats report: categories and order status.

{} It's a method of the class: DataStore{}

No Hooks.

Return

null. Nothing.

Usage

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

Code of DataStore::update_sql_query_params() WC 5.3.0

<?php
protected function update_sql_query_params( $query_args ) {
	global $wpdb;

	$products_where_clause      = '';
	$products_from_clause       = '';
	$where_subquery             = array();
	$order_product_lookup_table = self::get_db_table_name();

	$included_products = $this->get_included_products( $query_args );
	if ( $included_products ) {
		$products_where_clause .= " AND {$order_product_lookup_table}.product_id IN ({$included_products})";
	}

	$excluded_products = $this->get_excluded_products( $query_args );
	if ( $excluded_products ) {
		$products_where_clause .= "AND {$order_product_lookup_table}.product_id NOT IN ({$excluded_products})";
	}

	$included_variations = $this->get_included_variations( $query_args );
	if ( $included_variations ) {
		$products_where_clause .= " AND {$order_product_lookup_table}.variation_id IN ({$included_variations})";
	} else {
		$products_where_clause .= " AND {$order_product_lookup_table}.variation_id != 0";
	}

	$order_status_filter = $this->get_status_subquery( $query_args );
	if ( $order_status_filter ) {
		$products_from_clause  .= " JOIN {$wpdb->prefix}wc_order_stats ON {$order_product_lookup_table}.order_id = {$wpdb->prefix}wc_order_stats.order_id";
		$products_where_clause .= " AND ( {$order_status_filter} )";
	}

	$attribute_subqueries = $this->get_attribute_subqueries( $query_args );
	if ( $attribute_subqueries['join'] && $attribute_subqueries['where'] ) {
		// JOIN on product lookup if we haven't already.
		if ( ! $order_status_filter ) {
			$products_from_clause .= " JOIN {$wpdb->prefix}wc_order_stats ON {$order_product_lookup_table}.order_id = {$wpdb->prefix}wc_order_stats.order_id";
		}
		// Add JOINs for matching attributes.
		foreach ( $attribute_subqueries['join'] as $attribute_join ) {
			$products_from_clause .= ' ' . $attribute_join;
		}
		// Add WHEREs for matching attributes.
		$where_subquery = array_merge( $where_subquery, $attribute_subqueries['where'] );
	}

	if ( 0 < count( $where_subquery ) ) {
		$operator               = $this->get_match_operator( $query_args );
		$products_where_clause .= 'AND (' . implode( " {$operator} ", $where_subquery ) . ')';
	}

	$this->add_time_period_sql_params( $query_args, $order_product_lookup_table );
	$this->total_query->add_sql_clause( 'where', $products_where_clause );
	$this->total_query->add_sql_clause( 'join', $products_from_clause );

	$this->add_intervals_sql_params( $query_args, $order_product_lookup_table );
	$this->interval_query->add_sql_clause( 'where', $products_where_clause );
	$this->interval_query->add_sql_clause( 'join', $products_from_clause );
	$this->interval_query->add_sql_clause( 'select', $this->get_sql_clause( 'select' ) . ' AS time_interval' );
}