Skip to content

Instantly share code, notes, and snippets.

@jesseeproductions
Last active August 28, 2015 19:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jesseeproductions/b14f815d967f4851f641 to your computer and use it in GitHub Desktop.
Save jesseeproductions/b14f815d967f4851f641 to your computer and use it in GitHub Desktop.
The Events Calendar - Format Cost to include Comma
/*
* 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