woocommerce get_order_report_data显示order_item_id

问题描述 投票:0回答:1

我想通过get_order_report_data()显示order_item_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 thx。

php wordpress woocommerce
1个回答
0
投票

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

<?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'),
));
© www.soinside.com 2019 - 2024. All rights reserved.