Woocommerce - php 获取订单信息 [英] Woocommerce - php to get order information

查看:32
本文介绍了Woocommerce - php 获取订单信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取与 woocommerce 插件 (wordpress) 上的订单相关的数据.目前,我已经编写了自己的包含代码的插件:

I'm trying to get the data associated with an order on the woocommerce plugin (wordpress). Currently, I have written my own plugin that contains the code:

<?php 
global $woocommerce;
$order = new WC_Order($order_id);
$order_shipping_total = $order->get_shipping();
echo $order_shipping_total;
?>

这只是为了测试它,我不相信这是有效的 - 但我真正需要的是获取具有特定订单状态的订单列表,然后能够访问字段(例如名字)用于此列表中的每个订单.我该怎么做?另外,我需要包含哪些文件来完成这项工作?class-wc-order() 文件?

This is just to test it out, I don't believe this is working- BUT what I actually need is to get a list of the orders that have a certain order status, and then be able to access the fields(like first name) for each order in this list. How do I go about doing this? Also, what files do I include to make this work? The class-wc-order() file?

推荐答案

最近我为 XML 格式的订单数据导出工作.

Recently i worked for Export of Orders Data in 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!
}

这篇关于Woocommerce - php 获取订单信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆