Automattic\WooCommerce\Admin\API\Reports\Orders\Stats

Segmenter::segment_selections_orders()protectedWC 1.0

Returns column => query mapping to be used for order-level segmenting query (e.g. avg items per order or Net sales when segmented by coupons).

Method of the class: Segmenter{}

No Hooks.

Return

Array. Column => SELECT query mapping.

Usage

// protected - for code of main (parent) or child class
$result = $this->segment_selections_orders( $order_stats_table, $overrides );
$order_stats_table(string) (required)
Name of SQL table containing the order-level info.
$overrides(array)
Array of overrides for default column calculations.
Default: array()

Segmenter::segment_selections_orders() code WC 9.3.3

protected function segment_selections_orders( $order_stats_table, $overrides = array() ) {
	$columns_mapping = array(
		'num_items_sold'      => "SUM($order_stats_table.num_items_sold) as num_items_sold",
		'total_sales'         => "SUM($order_stats_table.total_sales) AS total_sales",
		'coupons'             => "SUM($order_stats_table.discount_amount) AS coupons",
		'coupons_count'       => 'COUNT( DISTINCT(coupon_lookup_left_join.coupon_id) ) AS coupons_count',
		'refunds'             => "SUM( CASE WHEN $order_stats_table.parent_id != 0 THEN $order_stats_table.total_sales END ) AS refunds",
		'taxes'               => "SUM($order_stats_table.tax_total) AS taxes",
		'shipping'            => "SUM($order_stats_table.shipping_total) AS shipping",
		'net_revenue'         => "SUM($order_stats_table.net_total) AS net_revenue",
		'orders_count'        => "COUNT($order_stats_table.order_id) AS orders_count",
		'avg_items_per_order' => "AVG($order_stats_table.num_items_sold) AS avg_items_per_order",
		'avg_order_value'     => "SUM($order_stats_table.net_total) / COUNT($order_stats_table.order_id) AS avg_order_value",
		'total_customers'     => "COUNT( DISTINCT( $order_stats_table.customer_id ) ) AS total_customers",
	);

	if ( $overrides ) {
		$columns_mapping = array_merge( $columns_mapping, $overrides );
	}

	return $columns_mapping;
}