Skip Navigation

[Resolved] Need to display numeric custom field in European decimal format

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

This topic contains 6 replies, has 4 voices.

Last updated by Gregor 6 years, 8 months ago.

Assigned support staff: Luo Yang.

Author
Posts
#208248

Site is built with WP-Types, Views, WooCommerce, WooCommerce Views. WooCommerce prices display correctly - European decimal format - but a numeric field added using WP-Types currently displays in American decimal format. How do I make this custom field display in European decimal format?

#208471

Luo Yang
Supporter

Languages: English (English ) Chinese (Simplified) (简体中文 )

Timezone: Asia/Hong_Kong (GMT+08:00)

Hi anthonyT,

I suggest you try create another shortcode for it, for example:

function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 2, '.', ' ');
}
add_shortcode('format_money', 'format_money');

number_format — Format a number with grouped thousands
hidden link

#208487

After I made the small adjustment for the European formatting desired -

number_format($price, 2, ',', '.'); 

in my case - this worked like a charm. Thanks!

#303210

May i ask how is this used exactly?

I added the code above in the functions.php of the theme.

Then on the view i added the shortcode "[format_money]".
I named my field "price". But it displays 0 value - 0,00.
It didnt seem to pick-up the value of price. I also tried having wpcf-price

#303215

Did you make sure to go to Views > Views Settings > Third-party shortcode arguments and add the short-code [format_money] there?

Here's what the code looks like in the template where I'm using this short-code:

<span style="font-weight: bold;">[format_money price=[wpv-post-field name="views_woo_price"]][/format_money]€</span>

Does that help?

#303227

Works for me. Thank you

#421274

Hello, I need exactly the same but can't get it work.

Like explained above, I added to my themes functions.php following:

function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 2, ',', '.');
}
add_shortcode('format_money', 'format_money');

My price field is called "property-price" so if iI understand correct the above, in my Content Template cell I have to put:

[format_money price=[wpv-post-field name="property-price"]][/format_money]€

The output is correctly formated now but the price value is missing, all I get is: 0,00€

I can't find -->> Views > Views Settings > Third-party shortcode arguments ....because it does not exist in the latest versions of Toolset I suppose ?!?!

What am I missing?

Thanks
Gregor