Sindbad~EG File Manager
<?php
namespace RealPress\Helpers;
use NumberFormatter;
/**
* Price
*/
class Price {
public static function render_price( $price, string $text_after_price = '' ) {
if ( ! is_numeric( $price ) ) {
return '';
}
$currency_symbol = self::get_currency_symbol();
$currency_position = Settings::get_setting_detail( 'group:general:fields:currency_position' );
$price_number = self::render_price_number( $price );
switch ( $currency_position ) {
case 'left':
$price = $currency_symbol . $price_number;
break;
case 'right':
$price = $price_number . $currency_symbol;
break;
case 'left_space':
$price = $currency_symbol . ' ' . $price_number;
break;
case 'right_space':
$price = $price_number . ' ' . $currency_symbol;
break;
default:
break;
}
return $price . ' ' . $text_after_price;
}
/**
* @param $price
*
* @return string
*/
public static function render_price_number( $price ) {
if ( $price === '' ) {
return '';
}
$thousands_separator = Settings::get_setting_detail( 'group:general:fields:currency_thousands_separator' );
$decimal_separator = Settings::get_setting_detail( 'group:general:fields:currency_decimals_separator' );
$number_of_decimals = Settings::get_setting_detail( 'group:general:fields:currency_number_decimals');
if ( empty( $number_of_decimals ) ) {
$number_of_decimals = 0;
}
return number_format( $price, $number_of_decimals, $decimal_separator, $thousands_separator );
}
/**
* @param string $currency_code
*
* @return array|false|mixed|\stdClass|string
*/
public static function get_currency_symbol( string $currency_code = '' ) {
if ( empty( $currency_code ) ) {
$currency_code = Settings::get_setting_detail( 'group:general:fields:currency_code' );
}
$currency_symbols = Config::instance()->get( 'currency:currency-symbol' );
if ( isset( $currency_symbols[ $currency_code ] ) ) {
return $currency_symbols[ $currency_code ];
}
return $currency_code;
}
}
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists