Last active
October 10, 2015 13:26
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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