BladeOne.php
2 years ago
CSV.php
2 years ago
Calculations.php
2 years ago
Currency.php
1 year ago
Device.php
2 years ago
Device_Cache.php
2 years ago
Dir.php
2 years ago
Number_Formatter.php
2 years ago
Request.php
1 year ago
Salt.php
1 year ago
Security.php
2 years ago
Server.php
2 years ago
Singleton.php
2 years ago
String_Util.php
2 years ago
URL.php
2 years ago
WP_Async_Request.php
2 years ago
WordPress_Site_Date_Format_Pattern.php
2 years ago
Currency.php
33 lines
| 1 | <?php |
| 2 | |
| 3 | namespace IAWP\Utils; |
| 4 | |
| 5 | use IAWP\Ecommerce\SureCart_Store; |
| 6 | use IAWPSCOPED\Illuminate\Support\Str; |
| 7 | /** @internal */ |
| 8 | class Currency |
| 9 | { |
| 10 | public static function format(int $amount_in_cents, bool $round_to_whole_dollars = \true) : string |
| 11 | { |
| 12 | if ($round_to_whole_dollars) { |
| 13 | $amount_in_cents = \round($amount_in_cents, -2); |
| 14 | } |
| 15 | if (\function_exists('wc_price')) { |
| 16 | if ($round_to_whole_dollars) { |
| 17 | $options = ['decimals' => 0]; |
| 18 | } else { |
| 19 | $options = null; |
| 20 | } |
| 21 | $formatted_value = \strip_tags(\wc_price($amount_in_cents / 100, $options)); |
| 22 | return $formatted_value; |
| 23 | } |
| 24 | if (\class_exists('\\SureCart\\Support\\Currency')) { |
| 25 | $currency_code = SureCart_Store::get_currency_code(); |
| 26 | $formatted_value = \SureCart\Support\Currency::format($amount_in_cents, $currency_code); |
| 27 | return $round_to_whole_dollars ? Str::before($formatted_value, ".") : $formatted_value; |
| 28 | } |
| 29 | // Fallback |
| 30 | return \strval(\intval($amount_in_cents / 100)); |
| 31 | } |
| 32 | } |
| 33 |