I am unable to find the product type when looking at the order object. I have tried


This does not give the product type and neither does


I have also looked for a function to achieve this here but can't see anything to achieve this.

I am able to get the line item type it seems but not the product type, seems odd

2 Answers 2


You would need to load the product to be able to see the product type as this is not a property of the order or the line item.

For example (using entity metadata wrappers):

$order = commerce_order_load($order_id);
$order_wrapper = entity_metadata_wrapper('commerce_order', $order);
foreach($order_wrapper->commerce_line_items as $line_item) {
  $type = $line_item->commerce_product->type->value();
  dpm($type, '$type');

Here is an example without using entity wrappers:

$order = commerce_order_load($order_id);
foreach($order->commerce_line_items[LANGUAGE_NONE] as $li) {
  $line_item = commerce_line_item_load($li['line_item_id']);
  $product = commerce_product_load($line_item->commerce_product[LANGUAGE_NONE][0]['product_id']);
  $type = $product->type;

I ended up just querying the database, here is what worked for me

$product_type = db_select('commerce_product', 'cp')
    ->fields('cp', array('type', 'product_id'))
    ->condition('cp.product_id', $product_id, '=')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.