Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Handle reversing the position of the currency symbol such that it displays
- * on the right, rather than the left, and optionally adds some space between
- * them.
- */
- class Tribe_Reverse_Currency_Position
- {
- public static $space = '';
- public static function take_effect($space = '') {
- self::$space = $space;
- add_filter('tribe_get_cost', array(__CLASS__, 'filter_cost'), 10, 3);
- }
- public static function filter_cost($cost, $post_id, $has_symbol) {
- if (!$has_symbol) return $cost;
- $symbol = self::post_currency_symbol($post_id);
- if (0 === strpos($cost, $symbol))
- return substr($cost, strlen($symbol)) . self::$space . $symbol;
- else return $cost;
- }
- protected static function post_currency_symbol($post_id) {
- if ( ! ($symbol = tribe_get_event_meta($post_id, '_EventCurrencySymbol', true)) )
- return tribe_get_option( 'defaultCurrencySymbol', '$' );
- else return $symbol;
- }
- }
- /**
- * Without any parameters it simply swaps the currency symbol so that it displays on
- * the right of the value. Optionally a string can be passed to separate the value
- * and the symbol with some space. Examples:
- *
- * Tribe_Reverse_Currency_Position::take_effect(' ');
- * Tribe_Reverse_Currency_Position::take_effect(' ');
- */
- Tribe_Reverse_Currency_Position::take_effect();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement