Message - Item already in cart (commerce)
&lt;?php
/**
 * Implements hook_form_FORMID_alter().
 */
function mymodule_form_commerce_cart_add_to_cart_form_alter(&amp;$form, &amp;$form_state) {
  $product_ids = mymodule_get_products_in_cart();

  $line_item = $form_state['line_item'];
  $product = commerce_product_load($line_item-&gt;commerce_product[LANGUAGE_NONE][0]['product_id']);
  if ($product-&gt;type == 'program') {
    if (in_array($product-&gt;product_id, $product_ids)) {
      // Product is already in cart! We only want to allow a quantity of 1,
      // so disable the submit button and change its text accordingly
      $form['submit']['#disabled'] = TRUE;
      $form['submit']['#value'] = t('Already in cart');
    }
  }
}   

/**
 * Return the product_id values for all products in the cart
 *
 * @return
 *  An array of product ids
 */
function mymodule_get_products_in_cart() {
  $product_ids = &amp;drupal_static(__FUNCTION__);

  if (!isset($product_ids)) {
    global $user;
    $product_ids = array();
    $order = commerce_cart_order_load($user-&gt;uid);
    if ($order) {
      $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
      foreach ($order_wrapper-&gt;commerce_line_items as $delta =&gt; $line_item_wrapper) {
        $product_wrapper = $line_item_wrapper-&gt;commerce_product;
        $product_ids[] = $product_wrapper-&gt;product_id-&gt;value();
      }
    }
  }

  return array_unique($product_ids);
}
?&gt;