PluginProbe
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More / 2.2.0
StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More v2.2.0
2.3.0 2.2.0 2.1.1 2.1.0 2.0.0 1.10.0 1.9.1 1.9.0 1.2.1 1.2.2 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.5.8 1.6.0 All 59 releases
storeengine / includes / utils / traits / currency.php

currency.php in StoreEngine — Complete eCommerce Solution with Memberships, Licensing, Affiliates & More 2.2.0, at includes/utils/traits/currency.php

434 lines 15.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace StoreEngine\Utils\traits;
4
5 use StoreEngine\Utils\Formatting;
6
7 trait Currency {
8
9 private static array $currency_symbols = [
10 'AED' => '&#x62f;.&#x625;',
11 'AFN' => '&#x60b;',
12 'ALL' => 'L',
13 'AMD' => 'AMD',
14 'ANG' => '&fnof;',
15 'AOA' => 'Kz',
16 'ARS' => '&#36;',
17 'AUD' => '&#36;',
18 'AWG' => 'Afl.',
19 'AZN' => '&#8380;',
20 'BAM' => 'KM',
21 'BBD' => '&#36;',
22 'BDT' => '&#2547;&nbsp;',
23 'BGN' => '&#1083;&#1074;.',
24 'BHD' => '.&#x62f;.&#x628;',
25 'BIF' => 'Fr',
26 'BMD' => '&#36;',
27 'BND' => '&#36;',
28 'BOB' => 'Bs.',
29 'BRL' => '&#82;&#36;',
30 'BSD' => '&#36;',
31 'BTC' => '&#3647;',
32 'BTN' => 'Nu.',
33 'BWP' => 'P',
34 'BYR' => 'Br',
35 'BYN' => 'Br',
36 'BZD' => '&#36;',
37 'CAD' => '&#36;',
38 'CDF' => 'Fr',
39 'CHF' => '&#67;&#72;&#70;',
40 'CLP' => '&#36;',
41 'CNY' => '&yen;',
42 'COP' => '&#36;',
43 'CRC' => '&#x20a1;',
44 'CUC' => '&#36;',
45 'CUP' => '&#36;',
46 'CVE' => '&#36;',
47 'CZK' => '&#75;&#269;',
48 'DJF' => 'Fr',
49 'DKK' => 'kr.',
50 'DOP' => 'RD&#36;',
51 'DZD' => '&#x62f;.&#x62c;',
52 'EGP' => 'EGP',
53 'ERN' => 'Nfk',
54 'ETB' => 'Br',
55 'EUR' => '&euro;',
56 'FJD' => '&#36;',
57 'FKP' => '&pound;',
58 'GBP' => '&pound;',
59 'GEL' => '&#x20be;',
60 'GGP' => '&pound;',
61 'GHS' => '&#x20b5;',
62 'GIP' => '&pound;',
63 'GMD' => 'D',
64 'GNF' => 'Fr',
65 'GTQ' => 'Q',
66 'GYD' => '&#36;',
67 'HKD' => '&#36;',
68 'HNL' => 'L',
69 'HRK' => 'kn',
70 'HTG' => 'G',
71 'HUF' => '&#70;&#116;',
72 'IDR' => 'Rp',
73 'ILS' => '&#8362;',
74 'IMP' => '&pound;',
75 'INR' => '&#8377;',
76 'IQD' => '&#x62f;.&#x639;',
77 'IRR' => '&#xfdfc;',
78 'IRT' => '&#x062A;&#x0648;&#x0645;&#x0627;&#x0646;',
79 'ISK' => 'kr.',
80 'JEP' => '&pound;',
81 'JMD' => '&#36;',
82 'JOD' => '&#x62f;.&#x627;',
83 'JPY' => '&yen;',
84 'KES' => 'KSh',
85 'KGS' => '&#x441;&#x43e;&#x43c;',
86 'KHR' => '&#x17db;',
87 'KMF' => 'Fr',
88 'KPW' => '&#x20a9;',
89 'KRW' => '&#8361;',
90 'KWD' => '&#x62f;.&#x643;',
91 'KYD' => '&#36;',
92 'KZT' => '&#8376;',
93 'LAK' => '&#8365;',
94 'LBP' => '&#x644;.&#x644;',
95 'LKR' => '&#xdbb;&#xdd4;',
96 'LRD' => '&#36;',
97 'LSL' => 'L',
98 'LYD' => '&#x62f;.&#x644;',
99 'MAD' => '&#x62f;.&#x645;.',
100 'MDL' => 'MDL',
101 'MGA' => 'Ar',
102 'MKD' => '&#x434;&#x435;&#x43d;',
103 'MMK' => 'Ks',
104 'MNT' => '&#x20ae;',
105 'MOP' => 'P',
106 'MRU' => 'UM',
107 'MUR' => '&#x20a8;',
108 'MVR' => '.&#x783;',
109 'MWK' => 'MK',
110 'MXN' => '&#36;',
111 'MYR' => '&#82;&#77;',
112 'MZN' => 'MT',
113 'NAD' => 'N&#36;',
114 'NGN' => '&#8358;',
115 'NIO' => 'C&#36;',
116 'NOK' => '&#107;&#114;',
117 'NPR' => '&#8360;',
118 'NZD' => '&#36;',
119 'OMR' => '&#x631;.&#x639;.',
120 'PAB' => 'B/.',
121 'PEN' => 'S/',
122 'PGK' => 'K',
123 'PHP' => '&#8369;',
124 'PKR' => '&#8360;',
125 'PLN' => '&#122;&#322;',
126 'PRB' => '&#x440;.',
127 'PYG' => '&#8370;',
128 'QAR' => '&#x631;.&#x642;',
129 'RMB' => '&yen;',
130 'RON' => 'lei',
131 'RSD' => '&#1088;&#1089;&#1076;',
132 'RUB' => '&#8381;',
133 'RWF' => 'Fr',
134 'SAR' => '&#x631;.&#x633;',
135 'SBD' => '&#36;',
136 'SCR' => '&#x20a8;',
137 'SDG' => '&#x62c;.&#x633;.',
138 'SEK' => '&#107;&#114;',
139 'SGD' => '&#36;',
140 'SHP' => '&pound;',
141 'SLL' => 'Le',
142 'SOS' => 'Sh',
143 'SRD' => '&#36;',
144 'SSP' => '&pound;',
145 'STN' => 'Db',
146 'SYP' => '&#x644;.&#x633;',
147 'SZL' => 'E',
148 'THB' => '&#3647;',
149 'TJS' => '&#x405;&#x41c;',
150 'TMT' => 'm',
151 'TND' => '&#x62f;.&#x62a;',
152 'TOP' => 'T&#36;',
153 'TRY' => '&#8378;',
154 'TTD' => '&#36;',
155 'TWD' => '&#78;&#84;&#36;',
156 'TZS' => 'Sh',
157 'UAH' => '&#8372;',
158 'UGX' => 'UGX',
159 'USD' => '&#36;',
160 'UYU' => '&#36;',
161 'UZS' => 'UZS',
162 'VEF' => 'Bs F',
163 'VES' => 'Bs.',
164 'VND' => '&#8363;',
165 'VUV' => 'Vt',
166 'WST' => 'T',
167 'XAF' => 'CFA',
168 'XCD' => '&#36;',
169 'XOF' => 'CFA',
170 'XPF' => 'XPF',
171 'YER' => '&#xfdfc;',
172 'ZAR' => '&#82;',
173 'ZMW' => 'ZK',
174 ];
175
176 public static function get_currency_symbols(): array {
177 return apply_filters( 'storeengine/currency_symbols', self::$currency_symbols );
178 }
179
180 /**
181 * Get Currency symbol.
182 *
183 * Currency symbols and names should follow the Unicode CLDR recommendation (https://cldr.unicode.org/translation/currency-names-and-symbols)
184 *
185 * @param string $currency Currency. (default: '').
186 *
187 * @return string
188 */
189 public static function get_currency_symbol( string $currency = '' ): string {
190 if ( ! $currency ) {
191 $currency = Formatting::get_currency();
192 }
193
194 $symbols = self::get_currency_symbols();
195 $symbol = $currency ? ( $symbols[ $currency ] ?? '' ) : '';
196
197 return apply_filters( 'storeengine/currency_symbol', $symbol, $currency );
198 }
199
200 /**
201 * Get full list of currency codes.
202 *
203 * Currency symbols and names should follow the Unicode CLDR recommendation (https://cldr.unicode.org/translation/currency-names-and-symbols)
204 *
205 * @return array
206 */
207 public static function get_currencies(): array {
208 static $currencies;
209
210 if ( ! isset( $currencies ) ) {
211 $currencies = array_unique( apply_filters( 'storeengine/currencies', [
212 'AED' => __( 'United Arab Emirates dirham', 'storeengine' ),
213 'AFN' => __( 'Afghan afghani', 'storeengine' ),
214 'ALL' => __( 'Albanian lek', 'storeengine' ),
215 'AMD' => __( 'Armenian dram', 'storeengine' ),
216 'ANG' => __( 'Netherlands Antillean guilder', 'storeengine' ),
217 'AOA' => __( 'Angolan kwanza', 'storeengine' ),
218 'ARS' => __( 'Argentine peso', 'storeengine' ),
219 'AUD' => __( 'Australian dollar', 'storeengine' ),
220 'AWG' => __( 'Aruban florin', 'storeengine' ),
221 'AZN' => __( 'Azerbaijani manat', 'storeengine' ),
222 'BAM' => __( 'Bosnia and Herzegovina convertible mark', 'storeengine' ),
223 'BBD' => __( 'Barbadian dollar', 'storeengine' ),
224 'BDT' => __( 'Bangladeshi taka', 'storeengine' ),
225 'BGN' => __( 'Bulgarian lev', 'storeengine' ),
226 'BHD' => __( 'Bahraini dinar', 'storeengine' ),
227 'BIF' => __( 'Burundian franc', 'storeengine' ),
228 'BMD' => __( 'Bermudian dollar', 'storeengine' ),
229 'BND' => __( 'Brunei dollar', 'storeengine' ),
230 'BOB' => __( 'Bolivian boliviano', 'storeengine' ),
231 'BRL' => __( 'Brazilian real', 'storeengine' ),
232 'BSD' => __( 'Bahamian dollar', 'storeengine' ),
233 'BTC' => __( 'Bitcoin', 'storeengine' ),
234 'BTN' => __( 'Bhutanese ngultrum', 'storeengine' ),
235 'BWP' => __( 'Botswana pula', 'storeengine' ),
236 'BYR' => __( 'Belarusian ruble (old)', 'storeengine' ),
237 'BYN' => __( 'Belarusian ruble', 'storeengine' ),
238 'BZD' => __( 'Belize dollar', 'storeengine' ),
239 'CAD' => __( 'Canadian dollar', 'storeengine' ),
240 'CDF' => __( 'Congolese franc', 'storeengine' ),
241 'CHF' => __( 'Swiss franc', 'storeengine' ),
242 'CLP' => __( 'Chilean peso', 'storeengine' ),
243 'CNY' => __( 'Chinese yuan', 'storeengine' ),
244 'COP' => __( 'Colombian peso', 'storeengine' ),
245 'CRC' => __( 'Costa Rican col&oacute;n', 'storeengine' ),
246 'CUC' => __( 'Cuban convertible peso', 'storeengine' ),
247 'CUP' => __( 'Cuban peso', 'storeengine' ),
248 'CVE' => __( 'Cape Verdean escudo', 'storeengine' ),
249 'CZK' => __( 'Czech koruna', 'storeengine' ),
250 'DJF' => __( 'Djiboutian franc', 'storeengine' ),
251 'DKK' => __( 'Danish krone', 'storeengine' ),
252 'DOP' => __( 'Dominican peso', 'storeengine' ),
253 'DZD' => __( 'Algerian dinar', 'storeengine' ),
254 'EGP' => __( 'Egyptian pound', 'storeengine' ),
255 'ERN' => __( 'Eritrean nakfa', 'storeengine' ),
256 'ETB' => __( 'Ethiopian birr', 'storeengine' ),
257 'EUR' => __( 'Euro', 'storeengine' ),
258 'FJD' => __( 'Fijian dollar', 'storeengine' ),
259 'FKP' => __( 'Falkland Islands pound', 'storeengine' ),
260 'GBP' => __( 'Pound sterling', 'storeengine' ),
261 'GEL' => __( 'Georgian lari', 'storeengine' ),
262 'GGP' => __( 'Guernsey pound', 'storeengine' ),
263 'GHS' => __( 'Ghana cedi', 'storeengine' ),
264 'GIP' => __( 'Gibraltar pound', 'storeengine' ),
265 'GMD' => __( 'Gambian dalasi', 'storeengine' ),
266 'GNF' => __( 'Guinean franc', 'storeengine' ),
267 'GTQ' => __( 'Guatemalan quetzal', 'storeengine' ),
268 'GYD' => __( 'Guyanese dollar', 'storeengine' ),
269 'HKD' => __( 'Hong Kong dollar', 'storeengine' ),
270 'HNL' => __( 'Honduran lempira', 'storeengine' ),
271 'HRK' => __( 'Croatian kuna', 'storeengine' ),
272 'HTG' => __( 'Haitian gourde', 'storeengine' ),
273 'HUF' => __( 'Hungarian forint', 'storeengine' ),
274 'IDR' => __( 'Indonesian rupiah', 'storeengine' ),
275 'ILS' => __( 'Israeli new shekel', 'storeengine' ),
276 'IMP' => __( 'Manx pound', 'storeengine' ),
277 'INR' => __( 'Indian rupee', 'storeengine' ),
278 'IQD' => __( 'Iraqi dinar', 'storeengine' ),
279 'IRR' => __( 'Iranian rial', 'storeengine' ),
280 'IRT' => __( 'Iranian toman', 'storeengine' ),
281 'ISK' => __( 'Icelandic kr&oacute;na', 'storeengine' ),
282 'JEP' => __( 'Jersey pound', 'storeengine' ),
283 'JMD' => __( 'Jamaican dollar', 'storeengine' ),
284 'JOD' => __( 'Jordanian dinar', 'storeengine' ),
285 'JPY' => __( 'Japanese yen', 'storeengine' ),
286 'KES' => __( 'Kenyan shilling', 'storeengine' ),
287 'KGS' => __( 'Kyrgyzstani som', 'storeengine' ),
288 'KHR' => __( 'Cambodian riel', 'storeengine' ),
289 'KMF' => __( 'Comorian franc', 'storeengine' ),
290 'KPW' => __( 'North Korean won', 'storeengine' ),
291 'KRW' => __( 'South Korean won', 'storeengine' ),
292 'KWD' => __( 'Kuwaiti dinar', 'storeengine' ),
293 'KYD' => __( 'Cayman Islands dollar', 'storeengine' ),
294 'KZT' => __( 'Kazakhstani tenge', 'storeengine' ),
295 'LAK' => __( 'Lao kip', 'storeengine' ),
296 'LBP' => __( 'Lebanese pound', 'storeengine' ),
297 'LKR' => __( 'Sri Lankan rupee', 'storeengine' ),
298 'LRD' => __( 'Liberian dollar', 'storeengine' ),
299 'LSL' => __( 'Lesotho loti', 'storeengine' ),
300 'LYD' => __( 'Libyan dinar', 'storeengine' ),
301 'MAD' => __( 'Moroccan dirham', 'storeengine' ),
302 'MDL' => __( 'Moldovan leu', 'storeengine' ),
303 'MGA' => __( 'Malagasy ariary', 'storeengine' ),
304 'MKD' => __( 'Macedonian denar', 'storeengine' ),
305 'MMK' => __( 'Burmese kyat', 'storeengine' ),
306 'MNT' => __( 'Mongolian t&ouml;gr&ouml;g', 'storeengine' ),
307 'MOP' => __( 'Macanese pataca', 'storeengine' ),
308 'MRU' => __( 'Mauritanian ouguiya', 'storeengine' ),
309 'MUR' => __( 'Mauritian rupee', 'storeengine' ),
310 'MVR' => __( 'Maldivian rufiyaa', 'storeengine' ),
311 'MWK' => __( 'Malawian kwacha', 'storeengine' ),
312 'MXN' => __( 'Mexican peso', 'storeengine' ),
313 'MYR' => __( 'Malaysian ringgit', 'storeengine' ),
314 'MZN' => __( 'Mozambican metical', 'storeengine' ),
315 'NAD' => __( 'Namibian dollar', 'storeengine' ),
316 'NGN' => __( 'Nigerian naira', 'storeengine' ),
317 'NIO' => __( 'Nicaraguan c&oacute;rdoba', 'storeengine' ),
318 'NOK' => __( 'Norwegian krone', 'storeengine' ),
319 'NPR' => __( 'Nepalese rupee', 'storeengine' ),
320 'NZD' => __( 'New Zealand dollar', 'storeengine' ),
321 'OMR' => __( 'Omani rial', 'storeengine' ),
322 'PAB' => __( 'Panamanian balboa', 'storeengine' ),
323 'PEN' => __( 'Sol', 'storeengine' ),
324 'PGK' => __( 'Papua New Guinean kina', 'storeengine' ),
325 'PHP' => __( 'Philippine peso', 'storeengine' ),
326 'PKR' => __( 'Pakistani rupee', 'storeengine' ),
327 'PLN' => __( 'Polish z&#x142;oty', 'storeengine' ),
328 'PRB' => __( 'Transnistrian ruble', 'storeengine' ),
329 'PYG' => __( 'Paraguayan guaran&iacute;', 'storeengine' ),
330 'QAR' => __( 'Qatari riyal', 'storeengine' ),
331 'RON' => __( 'Romanian leu', 'storeengine' ),
332 'RSD' => __( 'Serbian dinar', 'storeengine' ),
333 'RUB' => __( 'Russian ruble', 'storeengine' ),
334 'RWF' => __( 'Rwandan franc', 'storeengine' ),
335 'SAR' => __( 'Saudi riyal', 'storeengine' ),
336 'SBD' => __( 'Solomon Islands dollar', 'storeengine' ),
337 'SCR' => __( 'Seychellois rupee', 'storeengine' ),
338 'SDG' => __( 'Sudanese pound', 'storeengine' ),
339 'SEK' => __( 'Swedish krona', 'storeengine' ),
340 'SGD' => __( 'Singapore dollar', 'storeengine' ),
341 'SHP' => __( 'Saint Helena pound', 'storeengine' ),
342 'SLL' => __( 'Sierra Leonean leone', 'storeengine' ),
343 'SOS' => __( 'Somali shilling', 'storeengine' ),
344 'SRD' => __( 'Surinamese dollar', 'storeengine' ),
345 'SSP' => __( 'South Sudanese pound', 'storeengine' ),
346 'STN' => __( 'S&atilde;o Tom&eacute; and Pr&iacute;ncipe dobra', 'storeengine' ),
347 'SYP' => __( 'Syrian pound', 'storeengine' ),
348 'SZL' => __( 'Swazi lilangeni', 'storeengine' ),
349 'THB' => __( 'Thai baht', 'storeengine' ),
350 'TJS' => __( 'Tajikistani somoni', 'storeengine' ),
351 'TMT' => __( 'Turkmenistan manat', 'storeengine' ),
352 'TND' => __( 'Tunisian dinar', 'storeengine' ),
353 'TOP' => __( 'Tongan pa&#x2bb;anga', 'storeengine' ),
354 'TRY' => __( 'Turkish lira', 'storeengine' ),
355 'TTD' => __( 'Trinidad and Tobago dollar', 'storeengine' ),
356 'TWD' => __( 'New Taiwan dollar', 'storeengine' ),
357 'TZS' => __( 'Tanzanian shilling', 'storeengine' ),
358 'UAH' => __( 'Ukrainian hryvnia', 'storeengine' ),
359 'UGX' => __( 'Ugandan shilling', 'storeengine' ),
360 'USD' => __( 'United States (US) dollar', 'storeengine' ),
361 'UYU' => __( 'Uruguayan peso', 'storeengine' ),
362 'UZS' => __( 'Uzbekistani som', 'storeengine' ),
363 'VEF' => __( 'Venezuelan bol&iacute;var (2008–2018)', 'storeengine' ),
364 'VES' => __( 'Venezuelan bol&iacute;var', 'storeengine' ),
365 'VND' => __( 'Vietnamese &#x111;&#x1ed3;ng', 'storeengine' ),
366 'VUV' => __( 'Vanuatu vatu', 'storeengine' ),
367 'WST' => __( 'Samoan t&#x101;l&#x101;', 'storeengine' ),
368 'XAF' => __( 'Central African CFA franc', 'storeengine' ),
369 'XCD' => __( 'East Caribbean dollar', 'storeengine' ),
370 'XOF' => __( 'West African CFA franc', 'storeengine' ),
371 'XPF' => __( 'CFP franc', 'storeengine' ),
372 'YER' => __( 'Yemeni rial', 'storeengine' ),
373 'ZAR' => __( 'South African rand', 'storeengine' ),
374 'ZMW' => __( 'Zambian kwacha', 'storeengine' ),
375 ] ) );
376 }
377
378 return $currencies;
379 }
380
381 /**
382 * @return array
383 * @deprecated Use individual utility methods.
384 */
385 public static function get_currency_options(): array {
386 return apply_filters( 'storeengine/currency_options', [
387 'currency' => Formatting::get_currency(),
388 'currency_position' => Formatting::get_currency_position(),
389 'currency_thousand_separator' => Formatting::get_price_thousand_separator(),
390 'currency_decimal_separator' => Formatting::get_price_decimal_separator(),
391 'currency_decimal_limit' => Formatting::get_price_decimals(),
392 'rounding_precision' => Formatting::get_rounding_precision(),
393 'currency_symbol' => self::get_currency_symbol( Formatting::get_currency() ),
394 ] );
395 }
396
397 /**
398 * Get Base Currency Code.
399 *
400 * @return string
401 *
402 * @deprecated
403 */
404 public static function get_currency(): string {
405 return Formatting::get_currency();
406 }
407
408 /**
409 * @param string|float|int $price
410 * @param array $args
411 *
412 * @return string
413 * @deprecated
414 * @use \StoreEngine\Utils\Formatting::price()
415 *
416 */
417 public static function currency_format( $price, array $args = [] ): string {
418 if ( ! isset( $price ) ) {
419 return '';
420 }
421 $currency_options = self::get_currency_options();
422 $currency_symbol = $currency_options['currency_symbol'];
423 $currency_position = $currency_options['currency_position'];
424 $price = number_format(
425 (float) $price,
426 $currency_options['currency_decimal_limit'],
427 $currency_options['currency_decimal_separator'],
428 $currency_options['currency_thousand_separator']
429 );
430
431 return 'left' === $currency_position ? $currency_symbol . $price : $price . $currency_symbol;
432 }
433 }
434