Discussions

Get order items (in script)

Hi!

Which function can I get the order items? I need the quantity of items.
I use the commerce_order_load() function to get order data. But I can't find the items function(s).
Can Any help me? Which function could I use to get these data?

Posted: May 24, 2012

Comments

makgab on May 26, 2012

How can I count the items?

$order->commerce_line_items[LANGUAGE_NONE][0]['line_item_id'] // first item
$order->commerce_line_items[LANGUAGE_NONE][1]['line_item_id'] // second item
// ...etc.

var_dump( $order->commerce_line_items[LANGUAGE_NONE] );
// result (for example 2 items):
// array(2) {
//   [0]=>
//   array(1) {
//     ["line_item_id"]=>
//     string(1) "3"
//   }
//   [1]=>
//   array(1) {
//     ["line_item_id"]=>
//     string(1) "5"
//   }
// }