Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

php - 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 ]

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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:


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

$order = wc_get_order( $order_id );

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...