[Drupal] How to dynamically update Ubercart cart products count in Drupal?

| | 1 min read

A Drupal+Ubercart site with a store where users can purchase your products and no links to indicate the number of products anywhere in your site seems too annoying. It would be nice if there is a way to update the cart count as soon as a product is added to the cart.

Here is the code snippet to get the total number of contents in the cart:

<?php print count(uc_cart_get_contents()); ?>

You can theme the content accordingly to show the contents in style:

<?php print count(uc_cart_get_contents()); ?> items