Tribe__Tickets__Commerce__Currency::get_formatted_currency( int|string $amount, int $post_id, string|null $provider = null )

Get Formatted Currency According to a Provider.


Parameters

$amount

(int|string) (Required) The amount to format.

$post_id

(int) (Required) The id of the post with tickets.

$provider

(string|null) (Optional) The ticket provider class name.

Default value: null


Top ↑

Return

(mixed|void)


Top ↑

Source

File: src/Tribe/Commerce/Currency.php

	public function get_formatted_currency( $amount, $post_id, $provider = null ) {

		$currency = $this->get_currency_by_provider( $post_id, $provider );

		// Format the amount
		if (
			',' === $currency['decimal_point']
			&& false !== strpos( $amount, $currency['decimal_point'] )
		) {
			$amount = str_replace( ',', '.', $amount );
		}

		// Strip , from the amount (if set as the thousands separator)
		$amount = str_replace( ',', '', $amount );

		// Strip ' ' from the amount (if set as the thousands separator)
		$amount = str_replace( ' ', '', $amount );

		if ( empty( $amount ) ) {
			$amount = 0;
		}

		$formatted = number_format( $amount, $currency['number_of_decimals'], $currency['decimal_point'], $currency['thousands_sep'] );

		/**
		 * Filter the Formatted Currency.
		 *
		 * @since 4.11.0
		 *
		 * @param string $formatted The formatted amount.
		 * @param int    $amount    The original amount to be formatted.
		 * @param array  $currency  An array of currency formatting details.
		 */
		return apply_filters( 'tribe_format_amount', $formatted, $amount, $currency );
	}

Top ↑

Changelog

Changelog
Version Description
4.11.0 Introduced.