Commerce - check if this very product in presented in user's previous orders
If you have the Entity API module installed, you can do it using entity_metadata_wrappers and EntityFieldQuery like this:

$query = new EntityFieldQuery();

$query-&gt;entityCondition('entity_type', 'commerce_order')
  -&gt;entityCondition('uid', $uid);
$result = $query-&gt;execute();

if (isset($result['commerce_order'])) {
  $user_order_ids = array_keys($result['commerce_order']);
}

// Array for storing user's products.
$products = array();

foreach($user_order_ids as $user_order_id) {

  $o = entity_metadata_wrapper('commerce_order', $user_order_id);

  $line_items = $o-&gt;commerce_line_items-&gt;value();

  foreach ($line_items as $line_item) {
    $l = entity_metadata_wrapper('commerce_line_item', $line_item-&gt;line_item_id);
    $products[$o-&gt;status-&gt;value()][] = $l-&gt;commerce_product-&gt;product_id-&gt;value();
  }
}


This should give you a 2 dimensional array of products like this:

... (Array, 1 element)
  cart(Array, 2 elements)
    0 (String, 3 characters ) 203
    1 (String, 3 characters ) 158
  other_state(Array, 2 elements)
    0 (String, 3 characters ) 187