【问题标题】:How to grab item data from WooCommerce order如何从 WooCommerce 订单中获取商品数据
【发布时间】:2019-02-21 18:18:29
【问题描述】:

我需要从客户的订单中获取数据

需要带物品ID和数量。

试过了,没用

$item_data = $item_values->get_data();
foreach ($item_data as $item) {
    $product_id = $item['product_id'];
    $quantity = $item['quantity'];
}

【问题讨论】:

    标签: php wordpress woocommerce product orders


    【解决方案1】:

    您需要使用 foreach 循环来处理来自动态订单 ID $order_id (或来自 WC_Order 对象 em> $order):

    // Get an instance of the WC_Order object (if you don't have the WC_Order object yet)
    $order = wc_get_order( $order_id );
    
    // Loop through order items
    foreach( $order->get_items() as $item_id => $item ) { 
        // Get an instance of the WC_Product Object
        $product = $item->get_product();
    
        // Get the product ID
        $product_id = $product->get_id();
    
        // Get the item quantity
        $quantity = $item->get_quantity();
    }
    

    参考文献:

    【讨论】:

      猜你喜欢
      • 2019-02-23
      • 2021-04-02
      • 2017-09-17
      • 2018-01-24
      • 1970-01-01
      • 2021-01-07
      • 2019-01-26
      • 2017-04-04
      • 2019-03-24
      相关资源
      最近更新 更多