Skip Navigation

[Resolved] I want to add Comma every three digits

This thread is resolved. Here is a description of the problem and solution.

Problem: I would like to add commas to my number custom field when I display the value on the frontend of my site.

Solution: There is not a built-in way to do this in Toolset but a custom shortcode that can help. Add this code to your child theme's functions.php file:

add_shortcode( 'ts_format_number', 'ts_format_number_func');
function ts_format_number_func( $atts, $content ) {
    $int = (int) do_shortcode($content);
    return number_format($int, 0);
}

Then you can use it like this to format the number field value:

[ts_format_number][types field="price"][/types][/ts_format_number]

Relevant Documentation:
http://php.net/manual/en/function.number-format.php
https://codex.wordpress.org/Shortcode_API

This support ticket is created 6 years, 2 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
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 2 replies, has 2 voices.

Last updated by koheiY 6 years, 2 months ago.

Assisted by: Christian Cox.

Author
Posts
#613771

I have a types-field named "price".
The field type is Number.
For example, the value of "price" is "2000".

I want to show it as "2,000" in a view like this url.

hidden link

I don't use a woocommerce.

#613872

Hi, there is not a built-in way to do this in Toolset but I have a custom shortcode that can help. Add this code to your child theme's functions.php file:

add_shortcode( 'ts_format_number', 'ts_format_number_func');
function ts_format_number_func( $atts, $content ) {
    $int = (int) do_shortcode($content);
    return number_format($int, 0);
}

Then you can use it like this to format the number field value:

[ts_format_number][types field="price"][/types][/ts_format_number]
#614035

It's perfect! Thank you and have a good day!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.