Php如何确定订单是当月收货,php – 如何在woocommerce中按日期获取用户订单?

From your answer here,我认为是正确的.

你只需要在字段中添加date_query ……就像这样:

public function get_customer_total_order() {

$customer_orders = get_posts( array(

'numberposts' => - 1,

'meta_key' => '_customer_user',

'meta_value' => get_current_user_id(),

'post_type' => array( 'shop_order' ),

'post_status' => array( 'wc-completed' ),

'date_query' => array(

'after' => date('Y-m-d', strtotime('-10 days')),

'before' => date('Y-m-d', strtotime('today'))

)

) );

$total = 0;

foreach ( $customer_orders as $customer_order ) {

$order = wc_get_order( $customer_order );

$total += $order->get_total();

}

return $total;

}

附加读物:

内联关于如何使用get_order_report_data的问题,你可以这样做…你可以将它粘贴到你要测试的主题的functions.php中.

include_once( WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php');

$reports = new WC_Admin_Report();

$args = array(

'data' => array(

'_order_total' => array(

'type' => 'meta',

'function' => 'SUM',

'name' => 'total_sales'

),

),

'where' => array(

array(

'key' => 'post_date',

'value' => date( 'Y-m-d', strtotime( '01/01/2016' ) ), // starting date

'operator' => '>'

),

array(

'key' => 'post_date',

'value' => date( 'Y-m-d', strtotime( '02/01/2016' ) ), // end date...

'operator' => '

),

),

'where_meta' => array(

array(

'meta_key' => '_customer_user',

'meta_value' => '1', // customer id

'operator' => '='

)

),

);

$data = $reports->get_order_report_data($args);

print_r($data); // prints like: stdClass Object ( [total_sales] => 200 )

请注意上面代码中的评论……

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值