【发布时间】:2017-04-07 00:18:22
【问题描述】:
我需要根据数据范围获取每个产品的销售报告。这意味着我将输入产品 ID(或 ID)以及开始日期和结束日期,该函数将返回该产品在此(开始日期和结束日期)时间段内的销售数量。所以我尝试了WC_Admin_Report 和WC_Report_Sales_By_Product。我尝试过的代码是-
function the_dramatist_get_report(){
include_once( WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php');
include_once( WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-report-sales-by-product.php');
$reports = new WC_Report_Sales_By_Product();
$reports->start_date = strtotime('2016-11-11');
$reports->end_date = strtotime('2016-11-22');
$reports->product_ids = 15;
$total_items = absint( $reports->get_order_report_data( array(
'data' => array(
'_qty' => array(
'type' => 'order_item_meta',
'order_item_type' => 'line_item',
'function' => 'SUM',
'name' => 'order_item_count'
)
),
'where_meta' => array(
'relation' => 'OR',
array(
'type' => 'order_item_meta',
'meta_key' => array( '_product_id', '_variation_id' ),
'meta_value' => $reports->product_ids,
'operator' => 'IN'
)
),
'query_type' => 'get_var',
'filter_range' => true
) ) );
return $total_items;
}
但是当我已经测试过它应该是1 时,上面的代码正在返回0。所以如果你能帮我解决这个问题会更好。
如果您对完成此任务有任何其他想法,请随时分享。
【问题讨论】:
标签: php mysql wordpress woocommerce hook-woocommerce