Get number of items in cart of current anonymous user I need to get the number of items in cart of current anonymous customer on the site. I am using Drupal 7 and Drupal Commerce.
To load the current anonymous user cart, you can use commerce_cart_order_load something like this should suffice:

It gets the product count as separate line items and the product quantity including number of items per line item.

// Can leave blank or provide UID
$uid = 0; // anon
$product_count = 0;
$product_quantity_count = 0;

// Load cart order
if ($order = commerce_cart_order_load($uid)) {
  // Let's use the wrapper because it rocks
  $order_wrapper = entity_metadata_wrapper('commerce_order', $order);

  // Loop over line items and increment product counter
  foreach ($order_wrapper-&gt;commerce_line_items as $delta =&gt; $line_item_wrapper) {
    // If line item is a commerce product type
    if (in_array($line_item_wrapper-&gt;type-&gt;value(), commerce_product_line_item_types())) {
      // Increment counters
      // Individual product line item
      $product_count++;
      // Number of items of product line item (quantity)
      $product_quantity_count += $line_item_wrapper-&gt;quantity-&gt;value();    
    }
  }

  // Debug output
  drupal_set_message(t('User %uid has %count products in cart with a total of %quantity items', 
    array('%uid' =&gt; $uid, '%count' =&gt; $product_count, '%quantity' =&gt; $product_quantity_count)));
}