Skip to content

Instantly share code, notes, and snippets.

@andrasguseo
Created March 5, 2025 13:51
Show Gist options
  • Save andrasguseo/2a840028bf46058df15ae87b0bae502d to your computer and use it in GitHub Desktop.
Save andrasguseo/2a840028bf46058df15ae87b0bae502d to your computer and use it in GitHub Desktop.
TEC > Use space as the thousand separator (TEC only)
<?php
/**
* Format the event cost by using a space as the thousand separator.
*
* Usage: Add the snippet with Code Snippets or to your functions.php file.
* Enter the cost without a thousand separator, when creating the event.
*
* @since March 5, 2025 Initial version.
*
* @param double $cost the event cost
* @param int $event_id The ID of the event
*
* @return string The formatted cost with the currency symbol.
*
* @author: Andras Guseo
*
* Plugins required: The Events Calendar
*/
add_filter( 'tribe_events_cost_unformatted', function( $cost, $event_id ) {
$currency_symbol = get_post_meta( $event_id, '_EventCurrencySymbol', true );
$currency_position = get_post_meta( $event_id, '_EventCurrencyPosition', true );
$formatted_cost = number_format( $cost, 0, '.', ' ' );
if ( $currency_position == 'prefix' ) {
$cost = $currency_symbol . $formatted_cost;
} else {
$cost = $formatted_cost . $currency_symbol;
}
return $cost;
}, 10, 2 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment