Add line item quantity in block-commerce-cart-cart "title" I'm making the cart-content div hidden as the default (in the sidebar shopping cart block), only the title will be visible, when the user hovers on the block-commerce-cart-cart the cart-contents div will be visible to them. How do I show the user how many items the got it their cart when only the block-commerce-cart-cart is visible, which means adding the line item quantity into the header. Can anyone please help?
Here's a quick way using hook_block_view_alter():

function MYMODULE_block_view_alter(&amp;$data, $block) {
  if ($block-&gt;module == 'commerce_cart' &amp;&amp; $block-&gt;delta == 'cart') {
    global $user;
    if ($order = commerce_cart_order_load($user-&gt;uid)) {
      // Count the number of product line items on the order.
      $wrapper = entity_metadata_wrapper('commerce_order', $order);
      $quantity = commerce_line_items_quantity($wrapper-&gt;commerce_line_items, commerce_product_line_item_types());

      // If there are more than 0 product line items on the order...
      if ($quantity &gt; 0) {
        // Use the dynamic menu item title.
        $data['subject'] = format_plural($quantity, 'Shopping cart (1 item)', 'Shopping cart (@count items)');
      }
    }

  }
}


The above borrows code from commerce_cart_menu_item_title() to get the cart quantity, so if that's the string you want to output you can just call that function directly and not bother with re-implementing the code, in which case it would be as simple as:

function MYMODULE_block_view_alter(&amp;$data, $block) {
  if ($block-&gt;module == 'commerce_cart' &amp;&amp; $block-&gt;delta == 'cart') {
    $data['subject'] = commerce_cart_menu_item_title();
  }
}


The default return from commerce_cart_menu_item_title() will be at least 'Shopping Cart' (if the cart is empty) so this method should be pretty bulletproof.

Make sure you set the title of the block as an empty string on the block admin page (so the altered subject is used instead of a custom title) and that should work fine, e.g.: