1

Using commerceCurrency filter from the Craft commerce plugin, how can I add the currency name after the price instead of before the price, and drop the zeros when not necessary ?

For example :

{{ product.variants[0].salePrice | commerceCurrency(cart.currency) }}

€68.00

How can I output this :

68€

Thank you!

1

The current formatter looks at the currency's format and the current locale of the user. What locale are you set to?

You can drop the zeros with the stripZeros param in the currencyConvert filter. See docs here: https://craftcommerce.com/docs/twig-filters

4
  • The locale was set to English, whereas this will be a French website. So the currency format is now correct, thank you! But unfortunately this still doesn't work for dropping the zeros : {{ product.variants[0].salePrice | commerceCurrency(cart.currency, stripZeros = true) }}. Do you have any idea of what's going wrong, or should I contact the Craft Commerce support for this? Nov 14 '16 at 11:05
  • The twig filter params are positional like php function params. If you want to strip zeros you need that param in the fourth position. Nov 15 '16 at 9:36
  • Thank you, but I forgot to mention that I tried all of these possibilities, and none works for me to drop the zeros. {{ product.variants[0].salePrice | commerceCurrency(cart.currency, stripZeros = true) }}, {{ product.variants[0].salePrice | commerceCurrency(cart.currency, convert=true, format=true, stripZeros=true) }}, {{ product.variants[0].salePrice | commerceCurrency('EUR', convert=true, format=true, stripZeros=true) }}. Nov 16 '16 at 9:06
  • I finally contacted the Craft support and Brad told me that they recently fixed a bug (again) around this. He sent me a new NumberFormatter.php file (located in craft/app/etc/i18n) which fix this issue and that should be included in the next plugin update. Nov 17 '16 at 8:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.