Automattic\WooCommerce\Admin\API\Reports\Products\Stats

DataStore::update_sql_query_params()protectedWC 1.0

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

Method of the class: DataStore{}

No Hooks.

Return

null. Nothing (null).

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.

DataStore::update_sql_query_params() code WC 9.3.3

protected function update_sql_query_params( $query_args ) {
	global $wpdb;

	$products_where_clause      = '';
	$products_from_clause       = '';
	$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})";
	}

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

	$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} )";
	}

	$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' );
}