1

Edit: added code to describe how I'm performing the filtering as requested.

I'm trying to modify a woocommerce plugin, that implements the woocommerce class class-wc-admin-report.php. Specifically what I need to do is 1) filter by order status (which I've achieved) and 2) return the order status for each row (surprisingly harder than it would appear as the returned array is a collection defined by the parameter passed in ( an array of wc order data objects). The optoins for this parameter are apparently not documented, anywhere. The $dataParams object below is passed as a parameter to the get_order_report_data method of this class. The last item in the collection is my current hurdle (wc_status). I'm close, but need a woocomm guru to guide my way I think. TIA!

$dataParams = array(
        '_product_id' => array(
            'type' => 'order_item_meta',
            'order_item_type' => 'line_item',
            'function' => '',
            'name' => 'product_id'
        ),
        '_qty' => array(
            'type' => 'order_item_meta',
            'order_item_type' => 'line_item',
            'function' => 'SUM',
            'name' => 'quantity'
        ),
        '_line_subtotal' => array(
            'type' => 'order_item_meta',
            'order_item_type' => 'line_item',
            'function' => 'SUM',
            'name' => 'gross'
        ),
        '_line_total' => array(
            'type' => 'order_item_meta',
            'order_item_type' => 'line_item',
            'function' => 'SUM',
            'name' => 'gross_after_discount'
        ),
        '_line_tax' => array(
            'type' => 'order_item_meta',
            'order_item_type' => 'line_item',
            'function' => 'SUM',
            'name' => 'taxes'
        )
        ,
        'wc_status' => array(
            'type' => 'post',
            'name' => 'order_status'
        )

    );

 Sure - thx for the reply. So with <code>get_order_report_data</code> you pass in the dataParams, along with a few other params, I'm sure you're familiar with. The following is included immediately after the code from my original post:
if (!empty($_POST['variations'])) {
        $dataParams['_variation_id'] = array(
            'type' => 'order_item_meta',    
            'order_item_type' => 'line_item',
            'function' => '',
            'name' => 'variation_id'
        );
    }

Creating an aray of order status' to filter with:

    if($_POST['orderstatus']=='all'){
        $ostat =  array('completed','processing','on-hold','failed','cancelled');
    }else{
        $ostat = array($_POST['orderstatus']);
    }

    return $wc_report->get_order_report_data(array(
        'data' => $dataParams,
        'query_type' => 'get_results', //
        //'query_type' => 'get_results',
        'group_by' => 'product_id'.(empty($_POST['variations']) ? '' : ',variation_id'),
        'order_by' => $orderby,
        'limit' => (!empty($_POST['limit_on']) && is_numeric($_POST['limit']) ? $_POST['limit'] : ''),
        'filter_range' => ($_POST['report_time'] != 'all'),
        'order_types' => wc_get_order_types('order_count') 
        //added by TB
        ,'order_status' => $ostat  //applyijng the order status filter.
    ));
voidzero
  • 564
  • 1
  • 4
  • 11
  • can you add more details to your question? you said you achieved #1 but I don't see it in this code.. I know how `get_order_report_data` works and [this is an example](http://stackoverflow.com/a/35198366/251986).. – Reigel Gallarde Feb 09 '16 at 02:51

0 Answers0