我正在尝试获取与woocommerce插件(wordpress)上的订单相关的数据。目前,我已经编写了自己的插件,其中包含以下代码:
<?php
global $woocommerce;
$order = new WC_Order($order_id);
$order_shipping_total = $order->get_shipping();
echo $order_shipping_total;
?>这只是为了测试它,我不相信这是有效的-但我真正需要的是获得具有特定订单状态的订单的列表,然后能够访问该列表中每个订单的字段(如名字)。我该怎么做呢?另外,我需要包含哪些文件才能使其正常工作?class-wc-order()文件?
发布于 2013-08-14 14:29:15
最近,我在XML中导出订单数据。
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'meta_key' => '_customer_user',
'posts_per_page' => '-1'
);
$my_query = new WP_Query($args);
$customer_orders = $my_query->posts;
foreach ($customer_orders as $customer_order) {
$order = new WC_Order();
$order->populate($customer_order);
$orderdata = (array) $order;
// $orderdata Array will have Information. for e.g Shippin firstname, Lastname, Address ... and MUCH more.... Just enjoy!
}发布于 2016-02-05 18:52:28
要过滤出特定客户的订单,请使用其他参数meta_value
$user_id = get_current_user_id();
$args = array(
'post_type' => 'shop_order',
'post_status' => 'publish',
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'numberposts' => -1, // -1 for all orders
'posts_per_page' => '-1'
);
$my_query = new WP_Query($args);为特定客户加载订单的另一种方法:
$orders = get_posts( apply_filters( 'woocommerce_my_account_my_orders_query', array(
'numberposts' => 1, // -1 for all orders
'meta_key' => '_customer_user',
'meta_value' => $user_id,
'post_type' => 'shop_order',
'post_status' => 'publish'
) ) );另请参见here。
https://stackoverflow.com/questions/18198307
复制相似问题