tribe_format_currency( string $cost, null|int $post_id = null, null|string $currency_symbol = null, null|bool $reverse_position = null )

Receives a float and formats it with a currency symbol


Parameters

$cost

(string) (Required) pricing to format

$post_id

(null|int) (Optional)

Default value: null

$currency_symbol

(null|string) (Optional)

Default value: null

$reverse_position

(null|bool) (Optional)

Default value: null


Top ↑

Return

(string)


Top ↑

Source

File: src/functions/template-tags/general.php

	function tribe_format_currency( $cost, $post_id = null, $currency_symbol = null, $reverse_position = null ) {
		$post_id = Tribe__Main::post_id_helper( $post_id );

		if ( empty( $currency_symbol ) ) {
			$currency_symbol = tribe_get_option( 'defaultCurrencySymbol', '$' );

			/**
			 * Filters the currency symbol that will be used to format the price, defaults
			 * to the one set in the options.
			 *
			 * This will only apply if the currency symbol was not passed as a parameter.
			 *
			 * @since 4.7.7
			 *
			 * @param string $currency_symbol
			 * @param int $post_id
			 */
			$currency_symbol = apply_filters( 'tribe_currency_symbol', $currency_symbol, $post_id );
		}

		if ( null === $reverse_position ) {
			/**
			 * Filters whether the currency symbol that will be used to format the price should be
			 * prefixed (`false`) or appended (`true`) to the price value.
			 *
			 * This will only apply if the currency symbol reverse position not passed as a parameter.
			 *
			 * @since 4.7.7
			 *
			 * @param bool $reverse_position
			 * @param int  $post_id
			 */
			$reverse_position = apply_filters( 'tribe_reverse_currency_position', (bool) $reverse_position, $post_id );
		}

		// if no currency position was passed and we're not looking at a particular event,
		// let's get the default currency position
		if ( null === $reverse_position && ! $post_id ) {
			$reverse_position = tribe_get_option( 'reverseCurrencyPosition', false );
		}

		/**
		 * Add option to filter the cost value before is returned, allowing other providers to hook into it.
		 *
		 * @since 4.7.10
		 *
		 * @param string $cost
		 * @param int $post_id
		 */
		$cost = apply_filters( 'tribe_currency_cost', $cost, $post_id );

		$cost = $reverse_position
			? $cost . $currency_symbol
			: $currency_symbol . $cost;

		return $cost;
	}