WooCommerce Access orders that had discounts

懵懂的女人 提交于 2019-12-11 06:49:15

问题


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 ]

of every order that have product with discount

something like

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.


回答1:


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

Note: You can get the WC_Order object from $order_id variable (order ID) with:

$order = wc_get_order( $order_id );


来源:https://stackoverflow.com/questions/55559246/woocommerce-access-orders-that-had-discounts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!