PluginProbe
Datafeedr API / 1.1.2
Datafeedr API v1.1.2
1.4.2 1.0.125 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.24 1.0.25 1.0.26 1.0.27 1.0.28 1.0.29 1.0.3 1.0.30 1.0.31 1.0.32 1.0.33 All 181 releases
datafeedr-api / functions / price.php

price.php in Datafeedr API 1.1.2, at functions/price.php

56 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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' );