Reputation: 561
as we all know from here: https://docs.woocommerce.com/document/reports/ that woocommerce counts in the sales by date & sales by product By default, orders marked Processing, On Hold and Completed are counted as sales.
What if we want to make it count the orders counted as completed status only ?
N.B: we need this to work in the sales by product and sales by date tab
Upvotes: 2
Views: 1368
Reputation: 3117
By the way, there is now a setting in WooCommerce Reports to do this:
Upvotes: 0
Reputation: 3126
You can use the woocommerce_reports_get_order_report_data_args
filter to change the query. The following code should only show reports for completed orders for the 'sales by date' and 'sales by product' reports:
add_filter('woocommerce_reports_get_order_report_data_args', 'only_show_report_for_completed_orders');
function only_show_report_for_completed_orders( $args ) {
// When accessing the default sales by date report
if ( !isset( $_GET['tab'] ) || ( !isset( $_GET['report'] ) && isset( $_GET['tab'] ) && $_GET['tab'] == 'orders' ) ) {
$args['order_status'] = array( 'completed' );
// When accessing the specific reports
} elseif ( isset( $_GET['report'] ) && in_array( $_GET['report'], array( 'sales_by_date', 'sales_by_product' ) ) ) {
$args['order_status'] = array( 'completed' );
}
return $args;
}
This code snippet should be added to the functions.php of your child theme or via a plugin like Code Snippets.
Upvotes: 4