Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/240.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php woocommerce获取订单报告数据以显示订单项目id_Php_Wordpress_Woocommerce - Fatal编程技术网

Php woocommerce获取订单报告数据以显示订单项目id

Php woocommerce获取订单报告数据以显示订单项目id,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,我想通过获取订单报告数据来显示订单项目id 我可以使用数组显示产品id和订单id: array( '_product_id' => array( 'type' => 'order_item_meta', 'order_item_type' => 'line_item', 'function' => '', 'name' => 'product_id' ), 'order_id'

我想通过获取订单报告数据来显示订单项目id

我可以使用数组显示产品id和订单id:

array(
    '_product_id' => array(
        'type' => 'order_item_meta',
        'order_item_type' => 'line_item',
        'function' => '',
        'name' => 'product_id'
    ),
    'order_id' => array(
    'type' => 'order_item',
    'order_item_type' => 'line_item',
    'function' => '',
    'name' => 'order_id'
    )
)
但不适用于订单项目id


有什么建议吗?深度thx。

您可以使用此代码实现所需的结果

<?php   
    $sold_products = $wc_report->get_order_report_data(array(
    'data' => 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'
        )
    ),
    'query_type' => 'get_results',
    'group_by' => 'product_id',
    'where_meta' => '',
    'order_by' => 'quantity DESC',
    'order_types' => wc_get_order_types('order_count'),
    'filter_range' => TRUE,
    'order_status' => array('completed'),
));