currency format display: add dot and text

Home Forums Calendar Products Events Calendar PRO currency format display: add dot and text

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1276528
    Ren
    Participant

    how 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 COP

    Thank you so much

    #1277194
    Victor
    Member

    Hi 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!
    Victor

    #1277547
    Ren
    Participant

    thank 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 COP

    Thanks for your kind help

    #1277561
    Victor
    Member

    Hi 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!
    Victor

    #1277586
    Ren
    Participant

    Thank you so much. it worked like a charm!!

    have a nice day

    #1277675
    Victor
    Member

    Hey 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

Viewing 6 posts - 1 through 6 (of 6 total)
  • The topic ‘currency format display: add dot and text’ is closed to new replies.