Skip Navigation

[Resolved] Adding comma to values over 999

This support ticket is created 7 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Hong_Kong (GMT+08:00)

This topic contains 6 replies, has 2 voices.

Last updated by Charles 7 years, 3 months ago.

Assisted by: Luo Yang.

Author
Posts
#558401

Support,

I would like to add a comma to my custom field, mileage, so that a comma appears when needed.

Page with mileage field (see left side of page, 10750): hidden link

I was able to apply the comma to price, but not mileage.

Thanks,
Chuck

#558460

Dear Chuck,

Thanks for the details, there isn't such a built-in feature within Types plugin, as a workaround your can create a custom shortcode for it, for example, I did below modification in your website:
1) Add below codes into your theme/functions.php:

//Adding comma to values over 999
function format_money( $atts, $content ) {
    $content = do_shortcode($content);
    $content = number_format($content);
    return $content;
}
add_shortcode('format_money', 'format_money');

2) Edit the content template, "Motorcycle Post Submissions Layout" use above shortcode [format_money] to wrap the "mileage" field shortcode like this:

[format_money][types field='mileage'][/types][/format_money]

Please test again, check if it is what you want.

#558746

Luo,

It's working on this page: hidden link

But I tried the code on the map and it's not working. I got a script error when I tried it: hidden link

I assumed I would use the same code/format in the map view as the content template, but it didn't work.

Thanks,
Chuck

#558820

For the new problem, I checked the URL you mentioned above:
hidden link
click the map marker, I see the price value is: $5,500

Is this problem resolved? If you still need assistance for it, please point out where and how can I see the problem, thanks

#558823

The map shows the correct format for price, but not mileage. Mileage should have a comma.

Thanks,
Chuck

#558829

I added below codes into your theme/functions.php:

function display_number_func($output) {
    return number_format($output, 0);
}
add_filter("wpcf_fields_slug_mileage_value_display", "display_number_func");

It will add comma into the "mileage" field automatically, please test again, check if it is fixed. thanks

#558840

Fixed, looks great!

Thanks,
Chuck