CSS for zero price


Below is a modified version of function theme_uc_product_sell_price($price, $teaser) in uc_product.module that adds a CSS class to the sell_price div on product nodes (and maybe elsewhere?) when the price is $0 so that simple CSS can be optionally used in a theme to not display the price when it's $0, eg div.zero_price { display: none; }

function theme_uc_product_sell_price($price, $teaser) {
  $class = 'sell_price';
  if ($price == null || $price == 0 || $price=="0.00")
    $class .= ' zero_price';
  if ($teaser) {
    $output = '<span class="'. $class. '">';
    $output .= uc_currency_format($price);
    $output .= '</span>';
  else {
    $output = '<div class="'. $class. '">';
    $output .= t('Price: !price', array('!price' => uc_currency_format($price)));
    $output .= '</div>';
  return $output;

And for grid catalog display (uc_catalog.module) replace the line:

$product_table .= '<span class="catalog_grid_sell_price">'. uc_currency_format($product->sell_price) .'</span>';

with lines:

$sell_price_class = 'catalog_grid_sell_price'. ($product->sell_price == '0.00' ? ' zero_price': '');
$product_table .= '<span class="'. $sell_price_class. '">'. uc_currency_format($product->sell_price) .'</span>';
Ryan's picture
Joined: 08/07/2007
Juice: 15476
Re: CSS for zero price

This is a smart idea. For what it's worth, you can accomplish this at the theme level by overriding the core theme function in your theme's template.php so you don't have to hack core. Check out this FAQ for more info.

oliver coleman's picture
Bug Finder
Joined: 01/09/2008
Juice: 212
Yes, good point. We have a

Yes, good point. Smiling We have a multi-site install so it made more sense for us to hack core once instead of multiple themes.

keyinsight's picture
Joined: 03/24/2009
Juice: 4
Ubercart 2 Solution...

To implement this on Ubercart 2 place this code at the end of your template.php file:

function phptemplate_uc_product_price($price, $context, $options = array()) {
if ($price == null || $price == 0 || $price=="0.00")
  $output = '';
  else {
  $output = '<div class="product-info '. implode(' ', (array)$context['class']) .'">';
  $output .= uc_price($price, $context, $options);
  $output .= '</div>';

  return $output;

sevenshadow's picture
Joined: 05/27/2009
Juice: 46

keyinsight, I just wanted to thank you for this code. It saved me hours.

mspatz's picture
Joined: 07/09/2009
Juice: 2
Suppressing Zero Display

Been trying without success to suppress zeros being displayed for zero cost items in the UC shopping cart. I have tried adding the snippet of code at the bottom of my template.php file as suggested for Ubercart 2 solution and "cleared cache" under performance still with no luck.

Any help in this area would be greatly appreciated.

blasthaus's picture
Joined: 01/10/2010
Juice: 17
copying code from ubercart.org

Just a note for anyone who has difficulty implementing snippets like these. I noticed that when you copy code from most pages here that some invisible characters often show up (ie •) when pasting back into some text editors.(ie TextWrangler) If you show invisibles in your text area and just delete those invisibles, this code should work for you.

PaoloH's picture
Joined: 03/17/2012
Juice: 3
Same for Catalog Prices

Thanks for that code keyinsight, it worked perfectly (in my case changing £0.00 to £TBC). Any chance you (or anyone else out there) could help with doing the same on the catalog grid? The output I want to change is displayed like this:

<span class="catalog-grid-sell-price">
<span class="uc-price">£0.00</span>

I'd really appreciate it.