This support ticket is created 6 years, 10 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.
No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.
I have created a toolset number field. This includes a price (integer => 4852).
Now it is necessary to format this number as a price of the product (=> 4.852,- Euro).
How can I realize this?
To format a number as a current you need to use either JavaScript or PHP.
Which you use depends on if you are more comfortable with one or the other, but also where you intend to output the price.
I would think the best option would be to create a custom shortcode where you pass the field name as an attribute, and the PHP function gets the value of that field for the current post, then uses money_format to convert it into a currency format string which is then returned to the shortcode.
your solution worked perfect. But since a couple of time the shortcodes doesn´t work correctly.
As a college of you suggested, I changed all curly brackets into square brackets.
That works generally, but not for formatted price fields.
Code I am using in my (child) theme's functions.php file:
//* Shortcode to format the price (add thousands comma separator)
add_shortcode('format_money', 'sk_format_money');
function sk_format_money( $atts ) {
extract( shortcode_atts( array( 'price' => '0' ), $atts ) );
// $money = number_format( ( float )$price, 2, '.', ',' ); // if you want to show cents
$money = number_format( $price );
return $money;
}
Notes:
- My price field is a Number custom field
- My prices are entered without dollar signs or commas (i.e. 500000 and 40000 and 300 and 70)
- In Toolset -> Settings -> Front-end Content -> Third-party shortcode arguments -> Shortcodes registered manually, I added