您應該查看woocommerce文件並查找WC_Admin_Report
。你可以看到一些例子,並以你想要的方式工作。
我給你舉個例子。的print_r($data);
Array
(
[0] => stdClass Object
(
[quantity] => 4
[gross] => 140
[product_id] => 53
[order_item_name] => Happy Ninja
)
[1] => stdClass Object
(
[quantity] => 3
[gross] => 36
[product_id] => 70
[order_item_name] => Flying Ninja
)
[2] => stdClass Object
(
[quantity] => 1
[gross] => 10
[product_id] => 50
[order_item_name] => Patient Ninja
)
)
add_action('init', 'reports');
function reports() {
include_once(WC()->plugin_path().'/includes/admin/reports/class-wc-admin-report.php');
$wc_report = new WC_Admin_Report();
$data = $wc_report->get_order_report_data(array(
'data' => array(
'_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'
),
'_product_id' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => '',
'name' => 'product_id'
),
'order_item_name' => array(
'type' => 'order_item',
'function' => '',
'name' => 'order_item_name',
),
),
'group_by' => 'product_id',
'order_by' => 'quantity DESC',
'query_type' => 'get_results',
'limit' => 20,
'order_status' => array('completed', 'processing'),
));
print_r($data);
}
樣本輸出你的數據和將讓你和運行Item | Quantity
。
謝謝,你還可以展示我如何解析並以表格格式顯示?謝謝,真的很感激。 – Amjad