Problem to retrieve order line_items properties via WC REST API
-
Hi,
I’m having an issue with retrieving “order line items” properties via the WooCommerce REST API. To sync orders from a source site to a destination one, I used the following code snippet, but it failed to display any properties at all on orders:if (isset($order['line_items']) && is_array($order['line_items'])) { $line_items_data = array(); foreach ($order['line_items'] as $item) { $line_items_data[] = array( 'id' => $item['id'], 'name' => $item['name'], 'quantity' => $item['quantity'], 'price' => $item['price'], 'subtotal' => $item['subtotal'], 'total' => $item['total'], 'product_id' => $item['product_id'], ); } }
I initially removed the line ‘id’ => $item[‘id’] in $line_items_data[] array and the problem got temporarily solved, so now I had at least the above properties on the orders. but this led to the repetition of each order’s items and an increase in total price. This seems to be due to the lack of the identifier I had removed earlier. My question, therefore, is about the correct method of retrieving “id” in order line items.
Thanks in advance
- The topic ‘Problem to retrieve order line_items properties via WC REST API’ is closed to new replies.