shortcode – wpv-format-money

Many times it is important to store numbers in a plain format like “25970”, but maybe I need to display it like “25.970,00€” or  “$25,970.00”. This shortcode formats a number with grouped thousands.

I can add this shortcode:

// Money format shortcode (€ format)
add_shortcode('wpv-format-money', 'format_money');
function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 2, ',', '.');
}


// Money format shortcode ($ format)
add_shortcode('wpv-format-money', 'format_money');
function format_money( $atts ) {
extract( shortcode_atts( array(
'price' => '0'), $atts) );
return $price = number_format($price, 2, '.', ',');
}



Then I can use this shortcode anywhere:

[wpv-format-money price="..."]



The attribute “price” can get any custom field. For example:

[wpv-format-money price="[custom-field-1]"]



You can find this solution on this Toolset forum thread:

https://toolset.com/forums/topic/need-to-display-numeric-custom-field-in-european-decimal-format/