Get cart items and check for product of type X How do I?:


Get the current cart in commerce
For each item in the cart, check its product type?


I want to do the following:

foreach($cart_items as $item){
  if($item[product_type]=='X'){
    //perform a task
  }
}


I want to use this in the module code for a custom checkout pane.
Well this seems to work!

global $user;
$order = commerce_cart_order_load($user-&gt;uid);
$wrapper = entity_metadata_wrapper('commerce_order', $order);

foreach ($wrapper-&gt;commerce_line_items as $delta =&gt; $line_item_wrapper) {                                  
  $type = $line_item_wrapper-&gt;commerce_product-&gt;value()-&gt;type;   
  if($type=='X'){
    //perform a task
  }
}