Restrict WooCommerce Analytics to certain orders

Viewed 148

I would like only certain orders to be taken into account in the whole Analytics Section. I found the "woocommerce_reports_get_order_report_data_args" filter, but I am having trouble making it work.

My orders have some meta data, which I set up using ACF. I wrote this snippet :

add_filter('woocommerce_reports_get_order_report_data_args', 'only_show_report_for_some_orders');
function only_show_report_for_some_orders( $args ) {
  $args['where_meta'] = array(
    'relation' => 'AND',
    array(
      'meta_key' => 'type_commande',
      'meta_value' => array('commande','sous-depot-vente'),
      'operator' => 'IN'
    ),
  );
  return $args;
}

I get one error in the console (Internal Server Error) and also, most of the analytics are displayed (but for all my orders), so I guess I am not using the right filter, and my use of the where_meta parameter might be wrong...

Thanks in advance!!

1 Answers
add_filter('woocommerce_reports_get_order_report_data_args', 'woocommerce_reports_get_order_report_data_args');

function woocommerce_reports_get_order_report_data_args($args) {
    $args['where_meta'] = array(
        'meta_key' => 'type_commande',
        'operator' => 'in',
        'meta_value' => array('commande', 'sous-depot-vente')
    );
    return $args;
}

This is the hook you are looking for.

Related