Skip Navigation

[Resolved] Split: Show the number field in price format

This support ticket is created 4 years, 6 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/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 4 years, 6 months ago.

Assisted by: Waqar.

Author
Posts
#1929589

I want to show the number field in price format, I tried the previous forums like this https://toolset.com/forums/topic/add-currency-to-number-field but not working I really need help on this asap.

#1929679

Hi,

I tested the shortcode from the other ticket ( ref: https://toolset.com/forums/topic/display-numeric-value-as-currency/ ) and it worked as expected:


function format_my_number($atts)
{
    $atts = shortcode_atts(
        array(
        'num' => '',
        'sym' => '',
    ),
        $atts
    );
    $num = $atts['num'];
 
    return $atts['sym'].' '.number_format($num, 0, '.', ',');
}
add_shortcode('format-currency', 'format_my_number');

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.

After that, I used that shortcode in my template like this:


[format-currency num="[types field='post-price'][/types]" sym="$"]

Note: Please replace "post-price", with your actual number field's slug and "$" with the required currency symbol.

regards,
Waqar