Custom currencies formatting

By: Sam Rossetti | Asked: 11/04/2024
ForumsCategory: General questionsCustom currencies formatting
Sam RossettiSam Rossetti asked 1 month ago
Hello, i have a small problem with currencies formatting. In Switzerland we are used to have 2 decimals after our currency value such as : CHF 123.40 or CHF 10.25 But when we there is no decimals needed we replace it with a dash such as CHF 100.– instead of CHF 100.00 I am looking to find the hook that handles the currency formating but just found "frm_currency" with wich i could change the currency symbol and position, or "frm_setup_new_fields_vars" with which i could change the amount value but not the formatted value, it seems to happend later… Or does it happend at the JS level ?

Thanks for your help
1 Answers
Victor Font answered 1 month ago
Hooks operate at the server level either before the form is rendered in the browser or after the form is submitted. If you want this to happen in the browser, you need to use jQuery/JavaScript. See this: https://formidable-masterminds.com/formatting-fields-as-currency/
Sam RossettiSam Rossetti replied 1 month ago

Thanks Victor, so that happens at the JS level !

Sam RossettiSam Rossetti replied 1 month ago

I just tried with JS unactivated and the formatting is still done in the product line. I will dig deeper into that problem.

Victor Font replied 1 month ago

"I just tried with JS unactivated" What does this mean?

Sam RossettiSam Rossetti replied 1 month ago

I disabled JS to see how the numbers where formatted before any JS formatting. And my products are still listed as "product X : CHF 100.00". That means that FF has already formatted the price internally, as it is stored as 100 without any decimals.

Victor Font replied 1 month ago

Of course that's what would happen. You are running hooks that execute on the server. If you want the action to take place in the browser, deactivate your PHP snippets and use the JavaScript library I referenced.

Sam RossettiSam Rossetti replied 1 month ago

I think it’s more efficient to change how the server handles formatting instead of letting it do its business and then change again the format on the client side. It seems redundant to me 🙂

Victor Font replied 1 month ago

it is redundant which is exactly why I recommend not using the hooks for this and using JS. That is the most efficient way.

Sam RossettiSam Rossetti replied 1 month ago

I get your point. Thanks !

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right