WooCommerce 访问有折扣的订单

WooCommerce Access orders that had discounts

我想列出所有包含有折扣产品的订单,这样我就可以只根据有折扣的订单生成报告 并获取[订单号、订单日期、订单状态、订单总数、用户名、电子邮件和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
}  

这不是有效代码,但我需要知道从哪里开始。

您将在 $order 变量 WC_Order 对象) 上使用 WC_Order 方法 get_used_coupons(),例如:

if ( sizeof($order->get_used_coupons()) > 0 ) {
    // Your code goes here
}

现在要获取订单号、订单日期、订单状态、订单总额、用户名、电子邮件和phone,您将在以下线程中找到所有内容:


注意:您可以从 $order_id 变量 (订单 ID) 中获取 WC_Order 对象:

$order = wc_get_order( $order_id );