Skip to content

Instantly share code, notes, and snippets.

@henrytran9x
Last active October 10, 2015 13:26
Show Gist options
  • Save henrytran9x/1f52bdc6c071cb60fb3a to your computer and use it in GitHub Desktop.
Save henrytran9x/1f52bdc6c071cb60fb3a to your computer and use it in GitHub Desktop.
You are here Home » Drupal code snippets Programmatically show number of items in Drupal Commerce shopping cart
<?php
// http://kahthong.com/2012/08/programmatically-show-number-items-drupal-commerce-shopping-cart
global $user;
$quantity = 0;
$order = commerce_cart_order_load($user->uid);
if ($order) {
$wrapper = entity_metadata_wrapper('commerce_order', $order);
$line_items = $wrapper->commerce_line_items;
$quantity = commerce_line_items_quantity($line_items, commerce_product_line_item_types());
$total = commerce_line_items_total($line_items);
$currency = commerce_currency_load($total['currency_code']);
}
print format_plural($quantity, '1 item', '@count items');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment