具有折扣的WooCommerce Access订单 [英] WooCommerce Access orders that had discounts
问题描述
我想列出所有包含打折产品的订单,因此我可以仅基于打折的订单生成报告 并获取[订单号,订单日期,订单状态,订单总数,用户名,电子邮件和电话]
I would like to List all orders that contain products that had discounts on them, so I can generate a report based on only the orders that have discounts on them and get the [ order number, order date, order status, order total, user name, email and phone ]
每个有折扣产品的订单
类似
if (order_had_product_with_discount) {
get the [ order number, order date, order status, order total, user name, email and phone ] of this order
}
这不是有效的代码,但我需要知道从哪里开始.
It's not valid code but I need to know where to start.
推荐答案
You will use the WC_Order
method get_used_coupons()
on the $order
variable (the WC_Order
Object) like:
if ( sizeof($order->get_used_coupons()) > 0 ) {
// Your code goes here
}
现在获取订单号,订单日期,订单状态,订单总数,用户名,电子邮件和电话,您将在以下线程中找到所有内容:
Now to get the order number, the order date, the order status, the order total, the user name, the email and phone, you will find everything on the following threads:
- How to get WooCommerce order details
- Get Order items and WC_Order_Item_Product in Woocommerce 3
注意:您可以使用以下命令从$order_id
变量(订单ID)中获取WC_Order对象:
Note: You can get the WC_Order object from $order_id
variable (order ID) with:
$order = wc_get_order( $order_id );
这篇关于具有折扣的WooCommerce Access订单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!