skip to Main Content

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

2

Answers


  1. 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.

    Login or Signup to reply.
  2. By the way, there is now a setting in WooCommerce Reports to do this:

    • Go in your backend to Statistics -> Settings
    • Exclude all status you don’t want in your reports except "completed"
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search