【问题标题】:Order Item details in woocommerce在 woocommerce 中订购商品详情
【发布时间】:2016-08-19 03:11:14
【问题描述】:

我是 woocommerce 新手,想知道 sql 查询以获取特定订单 ID 的订单商品详细信息。

like、商品名称、数量、价格、线路税、线路总计、折扣(如果有)。

谢谢 阿杰

【问题讨论】:

  • 谷歌搜索 woocommerce sql get order by id 似乎得到了有用的结果
  • 我试过了,但几乎所有的都返回订单详细信息,但不返回订单商品详细信息

标签: woocommerce


【解决方案1】:

Woocommerce 为几乎所有目的提供了一套很棒的 AP​​I,如果您更喜欢非 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 )
}

【讨论】:

  • 感谢 Sark 的回复。但是,我正在寻找 smae 的 SQL 查询。
猜你喜欢
  • 1970-01-01
  • 2023-04-07
  • 2019-05-29
  • 2017-04-12
  • 2021-03-14
  • 2021-01-21
  • 1970-01-01
  • 1970-01-01
  • 2017-01-29
相关资源
最近更新 更多