Function uc_cart_get_contents() in uc_cart.module:
($cid = NULL, $action = NULL)


This function is used to return the contents of the user's cart.

When the function is called with no arguments, it will return the current customer's shopping cart. Alternately, you may specify a cart ID to load.

The function caches cart contents to prevent multiple database queries. If you need to load more than one cart, you're going to have to use the second argument to rebuild the cached contents.

  • $cid - the ID of the cart to load from the database (loads the current user's cart when NULL); defaults to NULL
  • $action - may be passed the string 'rebuild' to reload the items from the database; defaults to NULL
Return value:
An array of item arrays representing the products in the customer's shopping cart.

// Load the current shopping cart.
$items = uc_cart_get_contents();


// Display a message if the cart has more than 5 products.
$item_count = count($items);
  if (
$item_count > 5) {
drupal_set_message('Your cart contains more than 5 products.  Woohoo!');