/** * Get an event's cost * * @category Cost * @param null|int $postId (optional) * @param bool $withCurrencySymbol Include the currency symbol * * @return string Cost of the event. */ function tribe_get_cost($postId = null, $withCurrencySymbol = false) { $tribe_ecp = Tribe__Events__Main::instance(); $postId = Tribe__Events__Main::postIdHelper($postId); $cost = tribe_get_event_meta($postId, '_EventCost', true); if ($cost === '') { $cost = ''; } elseif ($cost === '0') { $cost = __("Free", 'tribe-events-calendar'); } else { $cost = esc_html($cost); } // check if the currency symbol is desired, and it's just a number in the field // be sure to account for european formats in decimals, and thousands separators if ($withCurrencySymbol && is_numeric(str_replace(array(',', '.'), '', $cost))) { $cost = tribe_format_currency($cost); } return apply_filters('tribe_get_cost', $cost, $postId, $withCurrencySymbol); }
<div class="tribe-event-meta tribe-event-meta-total-ticket-sales"> <strong><?php esc_html_e('Total Ticket Sales:', 'event-tickets-plus'); ?> </strong> <?php echo esc_html(tribe_format_currency(number_format($event_sales, 2), $event_id)); ?> </div> <div class="tribe-event-meta tribe-event-meta-total-site-fees"> <strong><?php esc_html_e('Total Site Fees:', 'event-tickets-plus'); ?> </strong> <?php echo esc_html(tribe_format_currency(number_format($event_fees, 2), $event_id)); ?> <div class="tribe-event-meta-note"> <?php echo apply_filters('tribe_events_orders_report_site_fees_note', '', $event, $organizer); ?> </div> </div> <?php } //end if ?> </td> </tr> </table> </div>
/** * Handler for the site fees column * * @param $item * * @return string */ public function column_site_fee($item) { $total = 0; foreach ($this->valid_order_items[$item['id']] as $line_item) { $total += $line_item['subtotal']; } return tribe_format_currency(number_format($this->calc_site_fee($total), 2)); }
/** * Formats a cost with a currency symbol * * @param int|float|string $cost Cost to format * * return string */ public function maybe_format_with_currency($cost) { // check if the currency symbol is desired, and it's just a number in the field // be sure to account for european formats in decimals, and thousands separators if (is_numeric(str_replace($this->get_separators(), '', $cost))) { $cost = tribe_format_currency($cost); } return $cost; }
/** * @param string $original_string_cost A string cost with or without currency symbol, * e.g. `10 - 20`, `Free` or `2$ - 4$`. * @param array|string $merging_cost A single string cost representation to merge or an array of * string cost representations to merge, e.g. ['Free', 10, 20, * 'Donation'] or `Donation`. * @param bool $with_currency_symbol Whether the output should prepend the currency symbol to the * numeric costs or not. * @param array $sorted_mins An array of non numeric price minimums sorted smaller to larger, * e.g. `['Really free', 'Somewhat free', 'Free with 3 friends']`. * @param array $sorted_maxs An array of non numeric price maximums sorted smaller to larger, * e.g. `['Donation min $10', 'Donation min $20', 'Donation min * $100']`. * * @return string|array The merged cost range. */ public function merge_cost_ranges($original_string_cost, $merging_cost, $with_currency_symbol, $sorted_mins = array(), $sorted_maxs = array()) { if (empty($merging_cost) || $original_string_cost === $merging_cost) { return $original_string_cost; } $_merging_cost = array_map(array($this, 'convert_decimal_separator'), (array) $merging_cost); $_merging_cost = array_map(array($this, 'numerize_numbers'), $_merging_cost); $numeric_merging_cost_costs = array_filter($_merging_cost, 'is_numeric'); $matches = array(); preg_match_all('!\\d+(?:([' . preg_quote($this->_supported_decimal_separators) . '])\\d+)?!', $original_string_cost, $matches); $this->_current_original_cost_separator = empty($matches[1][0]) ? '.' : $matches[1][0]; $matches[0] = empty($matches[0]) ? $matches[0] : array_map(array($this, 'convert_decimal_separator'), $matches[0]); $numeric_orignal_costs = empty($matches[0]) ? $matches[0] : array_map('floatval', $matches[0]); $all_numeric_costs = array_filter(array_merge($numeric_merging_cost_costs, $numeric_orignal_costs)); $cost_min = $cost_max = false; $merging_mins = array_intersect($sorted_mins, (array) $merging_cost); $merging_has_min = array_search(reset($merging_mins), $sorted_mins); $original_has_min = array_search($original_string_cost, $sorted_mins); $merging_has_min = false === $merging_has_min ? 999 : $merging_has_min; $original_has_min = false === $original_has_min ? 999 : $original_has_min; $string_min_key = min($merging_has_min, $original_has_min); if (array_key_exists($string_min_key, $sorted_mins)) { $cost_min = $sorted_mins[$string_min_key]; } else { $cost_min = empty($all_numeric_costs) ? '' : min($all_numeric_costs); } $merging_maxs = array_intersect($sorted_maxs, (array) $merging_cost); $merging_has_max = array_search(end($merging_maxs), $sorted_maxs); $original_has_max = array_search($original_string_cost, $sorted_maxs); $merging_has_max = false === $merging_has_max ? -1 : $merging_has_max; $original_has_max = false === $original_has_max ? -1 : $original_has_max; $string_max_key = max($merging_has_max, $original_has_max); if (array_key_exists($string_max_key, $sorted_maxs)) { $cost_max = $sorted_maxs[$string_max_key]; } else { $cost_max = empty($all_numeric_costs) ? '' : max($all_numeric_costs); } $cost = array_filter(array($cost_min, $cost_max)); if ($with_currency_symbol) { $formatted_cost = array(); foreach ($cost as $c) { $formatted_cost[] = is_numeric($c) ? tribe_format_currency($c) : $c; } $cost = $formatted_cost; } return empty($cost) ? $original_string_cost : array_map(array($this, 'restore_original_decimal_separator'), $cost); }