The answer lies in manipulating the Gravity Forms defaults for our chosen currency (in my case I use Australian dollars).
How to display whole dollar prices only
To display prices without the cents field on your Gravity Form fields merely add the following to your WordPress functions.php file:
add_filter( 'gform_currencies', 'update_currency' ); function update_currency( $currencies ) { $currencies['AUD'] = array( 'name' => __( 'Australian Dollar', 'gravityforms' ), 'symbol_left' => '$', 'symbol_right' => '', 'symbol_padding' => ' ', 'thousand_separator' => ',', 'decimal_separator' => '.', 'decimals' => 0 ); return $currencies; }
In the code above you’ll need to change the references to AUD and Australian Dollar to your currency needs. You’ll also need to amend the symbol_left value as appropriate. Below is a table of currency names and three letter abbreviations as included with Gravity Forms by default.
Currency name | Abbreviation | Symbol |
---|---|---|
Australian Dollar | AUD | $ |
Brazilian Real | BRL | R$ |
Canadian Dollar | CAD | $ |
Czech Koruna | CKZ | Kč |
Danish Krone | DKK | kr. |
Euro | EUR | € |
Hong Kong Dollar | HKD | HK$ |
Hungarian Forint | HUF | Ft |
Israeli New Sheqel | ILS | ₪ |
Japanese Yen | JPY | ¥ |
Malaysian Ringgit | MYR | RM |
Mexican Peso | MXN | $ |
Norwegian Krone | NOK | Kr |
New Zealand Dollar | NZD | $ |
Philippine Peso | PHP | Php |
Polish Zloty | PLN | zł |
Pound Sterling | GBP | £ |
Russian Ruble | RUB | pyб |
Singapore Dollar | SGD | $ |
South African Rand | ZAR | R |
Swedish Krona | SEK | Kr |
Swiss Franc | CHF | Fr. |
Taiwan New Dollar | TWD | $ |
Thai Baht | THB | ฿ |
U.S. Dollar | USD | $ |
This looked, great, I added this to my theme function.php and it worked, however for some reason it added $15 to the total? Why is that, I can’t see anything in the code that does it.
I apologise, I later discovered I was having trouble with a plug-in. It caused other glitches and I removed it. So I decided to try this again and it works wonderfully. If you ever figure out a way to round up though would be awesome!
Thanks!
This won’t work with the Stripe addon for GF, I tried but apparently Stripe needs decimals to work 🙁 any solutions?
How can I target a specific field with this method?
This came just in time for a Gravity Forms multiple form project. Neat fix using functions.php – thank you for sharing. Please continue to deliver such useful actionable content…especially Gravity Forms hacks.
Glad it helped 🙂
Thanks for the article. Could you please let me know if there’s a way to target this code to a specific form ID? I don’t want to apply this to all of my forms, just a specific one. Thanks again!