-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
63 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,52 @@ | ||
<?php | ||
|
||
/** | ||
* Append currency to an amount. | ||
* | ||
* @param float $amount The amount to append currency to. | ||
* @param array $options The options array. | ||
* @param bool $nbsp Whether to replace spaces with non-breaking spaces. | ||
* @param string $currency_key The currency key to use. | ||
* @return string The amount with currency appended. | ||
*/ | ||
function append_currency( $amount, $options, $nbsp = true, $currency_key = false ) { | ||
$amount = floatval( $amount ); | ||
class CampTix_Utility { | ||
/** | ||
* Append currency to an amount. | ||
* | ||
* @param float $amount The amount to append currency to. | ||
* @param array $options The options array. | ||
* @param bool $nbsp Whether to replace spaces with non-breaking spaces. | ||
* @param string $currency_key The currency key to use. | ||
* @return string The amount with currency appended. | ||
*/ | ||
public static function append_currency( $amount, $options, $nbsp = true, $currency_key = false ) { | ||
$amount = floatval( $amount ); | ||
|
||
$currencies = CampTix_Currency::get_currency_list(); | ||
|
||
if ( ! $currency_key ) { | ||
if ( isset( $options['currency'] ) ) { | ||
$currency_key = $options['currency']; | ||
} else { | ||
$currency_key = 'USD'; | ||
} | ||
} | ||
|
||
$currencies = CampTix_Currency::get_currency_list(); | ||
$currency = $currencies[ $currency_key ]; | ||
|
||
if ( ! $currency_key ) { | ||
if ( isset( $options['currency'] ) ) { | ||
$currency_key = $options['currency']; | ||
} else { | ||
$currency_key = 'USD'; | ||
if ( ! isset( $currency['decimal_point'] ) ) { | ||
$currency['decimal_point'] = 2; | ||
} | ||
} | ||
|
||
$currency = $currencies[ $currency_key ]; | ||
|
||
if ( ! isset( $currency['decimal_point'] ) ) { | ||
$currency['decimal_point'] = 2; | ||
} | ||
if ( isset( $currency['locale'] ) ) { | ||
$formatter = new NumberFormatter( $currency['locale'], NumberFormatter::CURRENCY ); | ||
$formatted_amount = $formatter->format( $amount ); | ||
} elseif ( isset( $currency['format'] ) && $currency['format'] ) { | ||
$formatted_amount = sprintf( $currency['format'], number_format( $amount, $currency['decimal_point'] ) ); | ||
} else { | ||
$formatted_amount = $currency_key . ' ' . number_format( $amount, $currency['decimal_point'] ); | ||
} | ||
|
||
if ( isset( $currency['locale'] ) ) { | ||
$formatter = new NumberFormatter( $currency['locale'], NumberFormatter::CURRENCY ); | ||
$formatted_amount = $formatter->format( $amount ); | ||
} elseif ( isset( $currency['format'] ) && $currency['format'] ) { | ||
$formatted_amount = sprintf( $currency['format'], number_format( $amount, $currency['decimal_point'] ) ); | ||
} else { | ||
$formatted_amount = $currency_key . ' ' . number_format( $amount, $currency['decimal_point'] ); | ||
} | ||
$formatted_amount = apply_filters( 'tix_append_currency', $formatted_amount, $currency, $amount ); | ||
|
||
$formatted_amount = apply_filters( 'tix_append_currency', $formatted_amount, $currency, $amount ); | ||
if ( $nbsp ) { | ||
$formatted_amount = str_replace( ' ', ' ', $formatted_amount ); | ||
} | ||
|
||
if ( $nbsp ) { | ||
$formatted_amount = str_replace( ' ', ' ', $formatted_amount ); | ||
return $formatted_amount; | ||
} | ||
|
||
return $formatted_amount; | ||
} | ||
} |