Home › Forums › Calendar Products › Events Calendar PRO › currency format display: add dot and text
- This topic has 6 replies, 2 voices, and was last updated 8 years, 11 months ago by
Ren.
-
AuthorPosts
-
April 30, 2017 at 11:43 am #1276528
Ren
Participanthow can i add the format to the currency that are shown in the events list.
for example. i have an event wich is $30000. Here in my country we are used to add a dot every 1000 units, so i want to display like this $30.000 and add COP
$30.000 COPThank you so much
May 2, 2017 at 6:18 am #1277194Victor
MemberHi Rene!
Thanks for reaching out to us and for using our plugins! 🙂
I am happy to help here!
Try adding the following code snippet to your theme’s functions.php file >
add_filter( 'tribe_get_cost', 'tribe_format_cost_field', 15, 3 );
function tribe_format_cost_field ( $cost, $post_id, $with_currency_symbol ) {
$cost_filtered = preg_replace('/[\$,]/', '', $cost);
$cost_pieces = explode(" - ", $cost_filtered);
if ( isset( $cost_pieces[0] ) && is_numeric( $cost_pieces[0] ) ) {
$cost = '$' . number_format( $cost_pieces[0], 2, ',', '.' ) . ' COP';
if ( isset( $cost_pieces[1] ) ) {
$cost .= ' - $' . number_format( $cost_pieces[1], 2, ',', '.' ) . ' COP';
}
}
return $cost;
}Does it work for you? Let me know
Best!
VictorMay 2, 2017 at 11:14 am #1277547Ren
Participantthank you so much. it worked.
but i dont want to include decimal after 0, so i want $30.000 COP instead of $30.000,00 COPThanks for your kind help
May 2, 2017 at 11:36 am #1277561Victor
MemberHi Rene!
Sure! you can change the code to look like the following and it will not output decimals >
add_filter( 'tribe_get_cost', 'tribe_format_cost_field', 15, 3 ); function tribe_format_cost_field ( $cost, $post_id, $with_currency_symbol ) { $cost_filtered = preg_replace('/[\$,]/', '', $cost); $cost_pieces = explode(" - ", $cost_filtered); if ( isset( $cost_pieces[0] ) && is_numeric( $cost_pieces[0] ) ) { $cost = '$' . number_format( $cost_pieces[0], 0, ',', '.' ) . ' COP'; if ( isset( $cost_pieces[1] ) ) { $cost .= ' - $' . number_format( $cost_pieces[1], 0, ',', '.' ) . ' COP'; } } return $cost; }I hope that helps!
Cheers!
VictorMay 2, 2017 at 12:26 pm #1277586Ren
ParticipantThank you so much. it worked like a charm!!
have a nice day
May 2, 2017 at 2:50 pm #1277675Victor
MemberHey Rene!
I’m glad it worked out for you! 🙂 Thanks for coming back and letting us know about it.
I’ll go ahead and close this thread but feel free to open a new one when you need it.
Good luck!
Victor -
AuthorPosts
- The topic ‘currency format display: add dot and text’ is closed to new replies.
