Posted by seanberto on August 17, 2009 at 4:00am
Hey Drupalistas,
This might be braindead simple, but I'd like to add a "cart" link to my primary menu to takes a site visitor to his/her Ubercart shopping cart. However, I only want this link to display if there are actual items in the cart.
I'm guessing that I can write a quick menu hook for this, or worse iterate through the primary navigation menu item array and just kill the link in the theme when the cart's empty. But it seems like this should be a solved problem.
Anyone got any thoughts?
Cheers,
Sean
ThinkShout.com

Comments
The following code snippet,
The following code snippet, place in template.php, did the trick on a Drupal 5 site I needed to do that on. Not sure if any changes in Ubercart 2. I just returned it as a variable in preprocess_page() to be used in the tpl.php file.
<?php$cart_items = uc_cart_get_contents();
if( !empty($cart_items) ){
$cart_link = l('cart', 'cart');
}
?>
Lev Tsypin
ThinkShout, Inc.
thinkshout.com | twitter.com/levelos