I am using the PHP library for the woocommerce REST API. I need to gather information regarding orders. I have tried many different ways of looping over the array that is returned from the get->orders function but cannot retrieve all the information I need.
Here is a var_dump of the returned array:
I can return the order number, order total, total items and date/time order created.
But I want to list out the items from the order, these items are in the 'line_items' array within the main array. The image doesn't show the items but it would be the same method to return the customer information from the 'billing_address' array again within the main array.
The current loop I have is this:
$orders = $connect->orders->get();
foreach( $orders as $order ) {
foreach( $order as $value ) {
echo $value["id"];
echo $value["total"];
echo $value["total_line_items_quantity"];
echo $value["status"];
}
}
Appreciate any help.
Note: here is the woocommerce REST API: http://woothemes.github.io/woocommerce-rest-api-docs/#view-list-of-orders
In response to Mihia
[shipping_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => GB
)
[note] =>
[customer_ip] => IP address
[customer_user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
[customer_id] => 1
[view_order_url] => data
[line_items] => Array
(
[0] => Array
(
[id] => 4
[subtotal] => 0.00
[subtotal_tax] => 0.00
[total] => 0.00
[total_tax] => 0.00
[price] => 0.00
[quantity] => 1
[tax_class] =>
[name] => Chips (Regular)
[product_id] => 8
[sku] => sku_8
[meta] => Array
(
)
)
[1] => Array
(
[id] => 5
[subtotal] => 0.00
[subtotal_tax] => 0.00
[total] => 0.00
[total_tax] => 0.00
[price] => 0.00
[quantity] => 1
[tax_class] =>
[name] => Cod (Regular)
[product_id] => 14
[sku] => cod01
[meta] => Array
(
)
)
)
[shipping_lines] => Array
(
)
[tax_lines] => Array
(
)
[fee_lines] => Array
(
)
[coupon_lines] => Array
(
)
[customer] => Array
(
[id] => 1
[created_at] => 2015-07-29T16:12:13Z
[email] => data
[first_name] =>
[last_name] =>
[username] => data
[role] => data
[last_order_id] => 22
[last_order_date] => 2015-07-30T14:01:54Z
[orders_count] => 5
[total_spent] => 7.96
[avatar_url] => http://2.gravatar.com/avatar/?s=96
[billing_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => GB
[email] => data
[phone] => data
)
[shipping_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => data
)
)
)
[8] => Array
(
[id] => 13
[order_number] => 13
[created_at] => 2015-07-29T17:04:02Z
[updated_at] => 2015-07-29T17:04:02Z
[completed_at] => 2015-07-29T16:04:02Z
[status] => processing
[currency] => GBP
[total] => 0.00
[subtotal] => 0.00
[total_line_items_quantity] => 1
[total_tax] => 0.00
[total_shipping] => 0.00
[cart_tax] => 0.00
[shipping_tax] => 0.00
[total_discount] => 0.00
[shipping_methods] =>
[payment_details] => Array
(
[method_id] =>
[method_title] =>
[paid] => 1
)
[billing_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => GB
[email] => data
[phone] => data
)
[shipping_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => GB
)
[note] =>
[customer_ip] => data
[customer_user_agent] => Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.10240
[customer_id] => 1
[view_order_url] => data
[line_items] => Array
(
[0] => Array
(
[id] => 3
[subtotal] => 0.00
[subtotal_tax] => 0.00
[total] => 0.00
[total_tax] => 0.00
[price] => 0.00
[quantity] => 1
[tax_class] =>
[name] => Chips (Regular)
[product_id] => 8
[sku] => sku_8
[meta] => Array
(
)
)
)
[shipping_lines] => Array
(
)
[tax_lines] => Array
(
)
[fee_lines] => Array
(
)
[coupon_lines] => Array
(
)
[customer] => Array
(
[id] => 1
[created_at] => 2015-07-29T16:12:13Z
[email] => data
[first_name] =>
[last_name] =>
[username] => data
[role] => data
[last_order_id] => 22
[last_order_date] => 2015-07-30T14:01:54Z
[orders_count] => 5
[total_spent] => 7.96
[avatar_url] => http://1.gravatar.com/avatar/?s=96
[billing_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => GB
[email] => data
[phone] => data
)
[shipping_address] => Array
(
[first_name] => Chris
[last_name] => data
[company] =>
[address_1] => data
[address_2] =>
[city] => data
[state] =>
[postcode] => data
[country] => GB
)
)
)