Hello,
Tell us what you are trying to do?
I would like to have the price field displayed properly. Currently it's showing as 4.2 instead of 4.20
Using this shortcode, [types field='views_woo_price'][/types]
What is the link to your site?
hidden link
Hi,
Thank you for contacting us and I'd be happy to assist.
To convert the format of the values stored in the custom fields, for showing them on the front-end, you can create a custom shortcode, as explained in this guide:
https://toolset.com/documentation/adding-custom-code/how-to-create-a-custom-shortcode/
For example:
add_shortcode('convert-decimal-places', 'convert_decimal_places_func');
function convert_decimal_places_func($atts) {
$a = shortcode_atts( array(
'number' => '',
'places' => '2',
), $atts );
if(!empty($a['number']) && !empty($a['places'])) {
$new = number_format((float)$a['number'], $a['places'], '.', '');
return $new;
}
}
The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.
This new shortcode accepts two attributes "number" and "places", and you can use it with your custom field's value, like this:
[convert-decimal-places number="[types field='views_woo_price'][/types]" places="2"]
As a result, the custom shortcode will ensure that the shortcode's output consists of a number of 2 decimal places.
regards,
Waqar
Hi Waqar,
Thank you for replying. The shortcode isn't working as described. I'm getting code returned instead of the number correctly formatted, [/types]' places='2']
Thanks for writing back.
I've performed some tests on my website with the same code, but couldn't reproduce this.
Can you please share temporary admin login details, along with the link to a page where this shortcode can be seen?
Note: Your next reply will be private and please make a complete backup copy, before sharing the access details.