Php 如何从商业订单中获取项目数据

Php 如何从商业订单中获取项目数据,php,wordpress,woocommerce,product,orders,Php,Wordpress,Woocommerce,Product,Orders,我需要从客户订单中获取数据 需要获取项目ID和数量 试过但不起作用 $item_data = $item_values->get_data(); foreach ($item_data as $item) { $product_id = $item['product_id']; $quantity = $item['quantity']; } 您需要对来自动态订单ID的订单项目使用一个foreach循环(或者来自WC\u-order对象$order): 参考资料:

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

需要获取项目ID和数量

试过但不起作用

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

您需要对来自动态订单ID的订单项目使用一个foreach循环(或者来自
WC\u-order
对象
$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();
}