I'm looking for a standard way of getting a user total sum of orders in a date range or for current month.
After exploring woocommerce source code, what I got is, woo is using something like this
$order_item_amounts = $this->get_order_report_data( array(
'data' => array(
'_line_total' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_amount'
),
'post_date' => array(
'type' => 'post_data',
'function' => '',
'name' => 'post_date'
),
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id'
),
),
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $this->product_ids,
'operator' => 'IN'
),
),
'group_by' => 'product_id, ' . $this->group_by_query,
'order_by' => 'post_date ASC',
'query_type' => 'get_results',
'filter_range' => true
) );
in class-wc-report-sales-by-product.php
But as you know, this works based on products not users.
from the above code,
$this->group_by_query
part holds the conditions for dates which can be found in woo source. My question is actually about how to use a builtin function of woocommerce to generate a list of orders based on given date range.
Thanks