Small feature request to add in the store currency admin, the ability to hide empty decimals from the price.
As an example, assuming the decimal is set to 2, the price formats as $10.00 or $10.49. I would love to see an option to hide the decimal if it's empty, so instead of $10.00, it would be $10, but if it was $10.49, show the decimal values.
The idea stems from point #7 in the article: http://blog.hubspot.com/blog/tabid/6307/bid/34118/7-Pricing-Mistakes-Tha...
Comments
Comment #1
tr commentedYou can do this by overriding theme_uc_price().
Comment #2
philsward commentedI don't even know what that means? I don't know how to override anything in the code. I don't code...
Comment #3
DanZ commentedThe display of almost everything in Drupal is controlled by themes. See https://drupal.org/documentation/theme for an explanation.
A theme function is a bit of PHP code that takes data and outputs HTML to display on a browser. A theme template does the same thing, except in a file, not a function. So, yes. Overriding these things requires some programming. If you can't program, that's OK. People who can program are pretty easy to find.
theme_uc_price() is the built-in function that themes prices. It uses uc_currency_format() to actually build the number string.
See Overriding themable output for directions on how to override that theme function. You'll want something that removes the decimal point if the price is close enough to an even dollar.
Or...you could try going to admin/store/settings/store, clicking on the "Currency format" vertical tab, and setting the "Number of decimal places" to zero.
Comment #4
philsward commented@DanZ Thanks for the general directions. For anyone else looking to do this:
(replace theme_uc_price with the name of your theme... ex. bartik_uc_price)
Works with panels too. Does NOT work with Views when "Display Price -> Format" is set to "Ubercart price". You have to set the format to "Numeric" to have views strip the .00. Bug maybe? If a views price format is set to "Ubercart Price" shouldn't it honor an overridden theme_uc_price?
Comment #5
philsward commented@DanZ Forgot to mention you can disable the decimal, but it doesn't disable it gracefully. Meaning, if you have a number with change ($9.92) it gets rid of the .92 which isn't exactly ideal :-/
Comment #7
haysuess commentedThe solution in #4 works for me, but ONLY in Views. When I print the price within my node template, I still get prices like $29.00.
Any ideas?