| 1 |
<?php |
| 2 |
|
| 3 |
// Exit if accessed directly |
| 4 |
if ( ! defined( 'ABSPATH' ) ) { |
| 5 |
exit; |
| 6 |
} |
| 7 |
|
| 8 |
function dfrapi_price_formatted( $int, $currency, $context = '' ) { |
| 9 |
$currency_code = dfrapi_price_currency_code( $currency, $context ); |
| 10 |
$price = dfrapi_price_int_converted( $int, $currency_code, $context ); |
| 11 |
|
| 12 |
// return apply_filters( 'dfrapi_format_price_' . $currency, $int ); |
| 13 |
} |
| 14 |
|
| 15 |
function dfrapi_price_int_converted( $int, $currency, $context = '' ) { |
| 16 |
$decimal_places = dfrapi_price_decimal_places( $currency, $context ); |
| 17 |
$decimal_separator = dfrapi_price_decimal_separator( $currency, $context ); |
| 18 |
$thousands_separator = dfrapi_price_decimal_separator( $currency, $context ); |
| 19 |
|
| 20 |
$price = number_format( ( $int / 100 ), $decimal_places, $decimal_separator, $thousands_separator ); |
| 21 |
|
| 22 |
return apply_filters( 'dfrapi_price_int_converted', $price, $int, $currency, $context ); |
| 23 |
} |
| 24 |
|
| 25 |
function dfrapi_price_currency_code( $currency, $context = '' ) { |
| 26 |
return apply_filters( 'dfrapi_price_currency_code', $currency, $context ); |
| 27 |
} |
| 28 |
|
| 29 |
function dfrapi_price_currency_symbol( $currency, $context = '' ) { |
| 30 |
return apply_filters( 'dfrapi_price_currency_symbol', dfrapi_currency_code_to_sign( $currency ), $context ); |
| 31 |
} |
| 32 |
|
| 33 |
function dfrapi_price_decimal_places( $currency, $context = '' ) { |
| 34 |
return apply_filters( 'dfrapi_price_decimal_places', 2, $currency, $context ); |
| 35 |
} |
| 36 |
|
| 37 |
function dfrapi_price_decimal_separator( $currency, $context = '' ) { |
| 38 |
$locale = localeconv(); |
| 39 |
|
| 40 |
return apply_filters( 'dfrapi_price_decimal_separator', $locale['decimal_point'], $currency, $context ); |
| 41 |
} |
| 42 |
|
| 43 |
function dfrapi_price_thousands_separator( $currency, $context = '' ) { |
| 44 |
$locale = localeconv(); |
| 45 |
|
| 46 |
return apply_filters( 'dfrapi_price_thousands_separator', $locale['thousands_sep'], $currency, $context ); |
| 47 |
} |
| 48 |
|
| 49 |
//add_filter( 'dfrapi_format_price_USD', function ( $int, $product ) { |
| 50 |
// $sign = dfrapi_currency_code_to_sign( 'USD' ); |
| 51 |
// $price = number_format( ( $int / 100 ), 2, '.', ',' ); |
| 52 |
// |
| 53 |
// return sprintf( '%s%s %s', $sign, $price, 'USD' ); |
| 54 |
//}, 10, 2 ); |
| 55 |
// |
| 56 |
//echo dfrapi_price_formatted( 12345, 'DKK', 'compset' ); |