Last active
August 28, 2015 19:28
-
-
Save jesseeproductions/b14f815d967f4851f641 to your computer and use it in GitHub Desktop.
The Events Calendar - Format Cost to include Comma
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* The Events Calendar - Format Cost to include Comma | |
* Works with $ Symbol, replace with other currency Symbol to work | |
* @version 3.11.1 | |
*/ | |
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] ); | |
if ( isset( $cost_pieces[1] ) ) { | |
$cost .= ' - $' . number_format( $cost_pieces[1] ); | |
} | |
} | |
return $cost; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment