我是woocommerce的新手,想知道sql查询以获取特定订单ID的订单商品详情。
喜欢,项目名称,qunatity,价格,行税,行总额,折扣(如果有)。
由于 AJ
答案 0 :(得分:0)
Woocommerce几乎为所有目的提供了一套很好的API,如果你更喜欢非sql方法,那么你可以通过使用WC API实现这一目标
$order = new WC_Order( $order_id );
/* get_items() retrives all the line items belong to that order
* you can also examine get_items() function for the actuall sql query used.
*/
foreach ( $order->get_items() as $item ) {
$product_id = (int) apply_filters( 'woocommerce_add_to_cart_product_id', $item['product_id'] );
$quantity = (int) $item['qty'];
$variation_id = (int) $item['variation_id'];
$variations = array();
$cart_item_data = apply_filters( 'woocommerce_order_again_cart_item_data', array(), $item, $order );
// using $product_id you can anything related to that product ( line item product )
}