print number of items in your UberCart shopping cart

Counts the number of items in an Ubercart shopping cart and returns the number to your page.tpl.php to be used as you wish. Could display shipping discount information if the item count reaches more than 5.

Note: this code can be edited to count quantities. For now it only counts unique items in your cart.

Snippet:

<?php
//in template.php:

#page variables
function _phptemplate_variables($hook, $vars = array()) {
    if (
$hook=='page'){
        if (
module_exists('uc_store')) {
           
$items = uc_cart_get_contents();
            if (!empty(
$items)) {
               
$vars['hasItems'] = count($items);
            }
        }
    }
    return
$vars;
}

//in page.tpl:
if ($hasItems){
    print
'<div class="cart-status">You have <strong>'.$hasItems.'</strong> items in <a href="/cart">your Cart</a></div>';
}
?>