'AED', // Arabic (UAE) → UAE Dirham 'be' => 'BYN', // Belarusian → Belarusian ruble (not in shop → fallback) 'bg' => 'BGN', // Bulgarian → Bulgarian lev 'hr' => 'EUR', // Croatian → Euro (adopted 2023) 'cs' => 'CZK', // Czech → Czech koruna 'da' => 'DKK', // Danish → Danish krone 'nl' => 'EUR', // Dutch → Euro 'en' => 'EUR', // English → Euro (default for EU context) 'et' => 'EUR', // Estonian → Euro 'fi' => 'EUR', // Finnish → Euro 'fr' => 'EUR', // French → Euro 'de' => 'EUR', // German → Euro 'el' => 'EUR', // Greek → Euro 'hu' => 'HUF', // Hungarian → Hungarian forint 'it' => 'EUR', // Italian → Euro 'lv' => 'EUR', // Latvian → Euro 'lt' => 'EUR', // Lithuanian → Euro 'no' => 'NOK', // Norwegian → Norwegian krone 'pl' => 'PLN', // Polish → Polish złoty 'pt-pt' => 'EUR', // Portuguese (Portugal) → Euro 'ro' => 'RON', // Romanian → Romanian leu 'sk' => 'EUR', // Slovak → Euro 'sl' => 'EUR', // Slovenian → Euro 'es' => 'EUR', // Spanish → Euro 'sv' => 'SEK', // Swedish → Swedish krona 'tr' => 'TRY', // Turkish → Turkish lira (not in shop → fallback) 'uk' => 'UAH', // Ukrainian → Ukrainian hryvnia (not in shop → fallback) ]; /** Fallback currency used when the natural currency is not supported. */ public const FALLBACK_CURRENCY = 'EUR'; /** * Default list of currencies configured in the shop's multicurrency plugin. * Used when STORE_CURRENCIES env variable is not set. * Keep in sync with WooCommerce multicurrency configuration. */ private const DEFAULT_SUPPORTED = 'PLN,EUR,AED,CZK,HUF,DKK,SEK,NOK,RON,BGN,GBP'; /** * Resolve a WPML language code to a shop-supported ISO 4217 currency. * * Returns an array with: * currency — ISO 4217 code to pass to the WooCommerce API * fallback — true if we had to fall back from the natural currency * natural_currency — (only when fallback=true) the natural currency for the language * reason — (only when fallback=true) 'unknown_language' | 'unsupported_currency' * * @param string|null $language WPML language code (e.g. 'de', 'pl', 'pt-pt') */ public static function resolve(?string $language): array { if ($language === null || $language === '') { return ['currency' => self::FALLBACK_CURRENCY, 'fallback' => false]; } $lang = strtolower(trim($language)); $natural = self::CURRENCY_MAP[$lang] ?? null; if ($natural === null) { return [ 'currency' => self::FALLBACK_CURRENCY, 'fallback' => true, 'reason' => 'unknown_language', ]; } if (!in_array($natural, self::supportedCurrencies(), true)) { return [ 'currency' => self::FALLBACK_CURRENCY, 'fallback' => true, 'reason' => 'unsupported_currency', 'natural_currency' => $natural, ]; } return ['currency' => $natural, 'fallback' => false]; } /** * Check whether a currency code is supported by the shop's multicurrency configuration. * * @param string $currency ISO 4217 code (comparison is case-insensitive) */ public static function isSupported(string $currency): bool { return in_array(strtoupper($currency), self::supportedCurrencies(), true); } /** * @return string[] */ private static function supportedCurrencies(): array { $raw = Env::get('STORE_CURRENCIES', self::DEFAULT_SUPPORTED); return array_values(array_filter(array_map('trim', explode(',', strtoupper($raw))))); } }