Commerce get product id's from order My question is simple: How do I get the product id's from a commerce order with Drupal code?
I have something like this at the moment:

  $orders = commerce_order_load_multiple(array(), array('status' =&gt; 'pending'), TRUE);
  foreach($orders as $order) {
    foreach ($order-&gt;commerce_line_items['und'] as $line) {
        $line_id = $line['line_item_id'];
        // ... product id, where are you?
    }


Hopefully somebody is able to answer this question :)
Using the entity metadata wrapper, you could also do:

foreach (commerce_order_load_multiple(array(), array('status' =&gt; 'pending'), TRUE) as $order) {
  $product_ids = array();
  foreach (entity_metadata_wrapper('commerce_order', $order)-&gt;commerce_line_items as $delta =&gt; $line_item_wrapper) {
    if (in_array($line_item_wrapper-&gt;type-&gt;value(), commerce_product_line_item_types())) {
      $product_ids[] = $line_item_wrapper-&gt;commerce_product-&gt;raw();
    }
  }
}


The important part here is checking the type of the line item, so you don't end up including shipping line items or other types of line items in your list of product IDs. Additionally, with the wrapper notice that I used the "raw" value of the commerce_product field on the line item. This is because the "value" would be the fully loaded referenced product, while the "raw" value is simply the product ID.