1

What I am trying to achieve is to theme the price format the following way. I only want to remove the decimals when they are 00.

For example €5,00 should be €5, but €5,50 should remain the same, not €5,5. I found a forum about this problem but I dont know how to implement it, especially overriding theme_uc_product_price() as suggested here.

JSW189
  • 6,267
  • 11
  • 44
  • 72
user1031742
  • 404
  • 1
  • 6
  • 20

1 Answers1

0

Those links suggest using either the Computed Field Module or a Preprocess function but it would be simple with a bit of JQuery:

Let's say you have a div like so:

<div class="field-price">€ 5,00</div> 

You could then target that element with a replace:

$('.field-price:contains(",00")').html(function(i, h) {
  return h.replace(/00/g, '');
});​

I wrote a demo here:

http://jsfiddle.net/JySHQ/1/

Note please indicate what version of Drupal you have and then I give give you some hints as how to implement as Javascript is different in Drupal 6 vs. Drupal 7

Danny Englander
  • 2,005
  • 5
  • 26
  • 41
  • Hi, thank you for answer. I use drupal 6. Your example looks really useful. I am concerned about users without javascript as well because believe it or not, according analytics almost 30%of my visitors don't have javascript enabled. – user1031742 Feb 12 '12 at 04:52
  • This seems like a cosmetic change more than anything so since it's Javascript, it will degrade gracefully and simply show the trailing zeros. I looked at the other solutions in your links and they seemed fairly kludgy to implement so I came up with the Jquery. If you need it for Drupal 6, let me know and I'll put some code here as well. – Danny Englander Feb 12 '12 at 16:50
  • If you would be so kind I would ask for a code overriding theme_uc_product_price() as suggested by maintainer of the project ubercart. I would say that this code will be of great use for many european shop owners who don§t need to display trailing zeroes. Thank you very much. – user1031742 Feb 13 '12 at 05:01