Quantcast
Channel: KahThong.com - commerce
Viewing all articles
Browse latest Browse all 2

Programmatically show number of items in Drupal Commerce shopping cart

$
0
0

This is a short code snippet to programmatically show number of items in your Drupal Commerce shopping cart block.

You can use this code anywhere, in your theme.

<?php
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');


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles





Latest Images