Для одного размещенного заказа, в котором есть 3 продукта, мне нужно получить структуру данных в формате:
[items] => Array
(
[0] => Array
(
[sku] => Product 1 sku
[qty] => Product 1 qty
[price] => Product 1 price
[weight] =>
[discount] =>
[line_ref] =>
)
[1] => Array
(
[sku] => Product 2 sku
[qty] => Product 2 qty
)
[2] => Array
(
[sku] => Product 3 sku
[qty] => Product 3 qty
)
)
Вот мой код:
$order = new WC_Order( $order_id );
// Get the order ID
$order_id = $order->get_id();
// Get data from Items
foreach ( $order->get_items() as $item_key => $item_values ) {
$product_id = $item_values->get_product_id(); // the Product id
$product = $item_values->get_product(); // the WC_Product object
$item_data = $item_values->get_data();
$item = array(array(
'sku' => $product->get_sku(),
'qty' => $item_data['quantity'],
'price' => $product->get_price(),
'weight' => '',
'discount' => '',
'line_ref' => ''
),
array(
'sku' => $product->get_sku(),
'qty' => $item_data['quantity'],
)
);
}
print_r($item);
Как можноЯ достиг этого?
Я получаю единственные данные о самом первом продукте, представленном в Заказе.И если я сделаю print_r ($ item);затем в цикле foreach повторяются все данные в зависимости от количества товаров в ордере.