ComposedResolver.php
1 week ago
Factory.php
1 week ago
HelperByLanguage.php
1 week ago
HelperByLocation.php
1 week ago
Resolver.php
1 week ago
ResolverForContext.php
1 week ago
ResolverForDefault.php
1 week ago
ResolverForModeLanguage.php
1 week ago
ResolverForModeLocation.php
1 week ago
HelperByLocation.php
30 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\MultiCurrency\Resolver; |
| 4 | |
| 5 | use WCML\MultiCurrency\Geolocation; |
| 6 | use WCML\MultiCurrency\Settings; |
| 7 | use WPML\FP\Fns; |
| 8 | |
| 9 | class HelperByLocation { |
| 10 | |
| 11 | private static $getCurrency; |
| 12 | |
| 13 | public static function getCurrencyByUserCountry() { |
| 14 | if ( ! self::$getCurrency ) { |
| 15 | self::$getCurrency = Fns::memorize( function() { |
| 16 | $clientCountry = Geolocation::getUserCountry(); |
| 17 | $currency = Geolocation::getOfficialCurrencyCodeByCountry( $clientCountry ); |
| 18 | |
| 19 | if ( ! Settings::isValidCurrencyByCountry( $currency, $clientCountry ) ) { |
| 20 | $currency = Settings::getFirstAvailableCurrencyByCountry( $clientCountry ); |
| 21 | } |
| 22 | |
| 23 | return $currency ?: null; |
| 24 | } ); |
| 25 | } |
| 26 | |
| 27 | return call_user_func( self::$getCurrency ); |
| 28 | } |
| 29 | } |
| 30 |