AI
3 days ago
Beacon
3 days ago
ContextualInfo
3 days ago
Debug
3 days ago
Exception
3 days ago
FreeShipping
3 days ago
ImporterExporter
3 days ago
Order
3 days ago
Rates
3 days ago
Rule
3 days ago
ShippingMethod
3 days ago
ShippingMethodsIntegration
3 days ago
Tax
3 days ago
views
3 days ago
Beacon.php
3 days ago
DefaultRulesSettings.php
3 days ago
MultiCurrency.php
3 days ago
RulesSettingsField.php
3 days ago
RulesTableSettings.php
3 days ago
ShippingMethodSingle.php
3 days ago
UserFeedback.php
3 days ago
MultiCurrency.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPDesk\FS\TableRate; |
| 4 | |
| 5 | use FSVendor\WPDesk\PluginBuilder\Plugin\Hookable; |
| 6 | use FSVendor\Psr\Log\LoggerInterface; |
| 7 | |
| 8 | /** |
| 9 | * Can convert from shop currency to current currency. |
| 10 | */ |
| 11 | class MultiCurrency implements Hookable { |
| 12 | |
| 13 | /** |
| 14 | * @var LoggerInterface |
| 15 | */ |
| 16 | private $logger; |
| 17 | |
| 18 | /** |
| 19 | * @var string |
| 20 | */ |
| 21 | private $filter_prefix; |
| 22 | |
| 23 | /** |
| 24 | * @param LoggerInterface $logger |
| 25 | * @param string $filter_prefix |
| 26 | */ |
| 27 | public function __construct( LoggerInterface $logger, string $filter_prefix ) { |
| 28 | $this->logger = $logger; |
| 29 | $this->filter_prefix = $filter_prefix; |
| 30 | } |
| 31 | |
| 32 | public function hooks() { |
| 33 | add_filter( 'flexible_shipping_value_in_currency', [ $this, 'flexible_shipping_value_in_currency' ], PHP_INT_MAX, 2 ); |
| 34 | } |
| 35 | |
| 36 | public function flexible_shipping_value_in_currency( $amount, $base_currency_amount = null ) { |
| 37 | if ( $base_currency_amount && $amount !== $base_currency_amount ) { |
| 38 | // Already converted. |
| 39 | return $amount; |
| 40 | } |
| 41 | |
| 42 | return (float) apply_filters( $this->filter_prefix . '/currency-switchers/amount', $amount, $this->logger ); |
| 43 | } |
| 44 | |
| 45 | } |
| 46 |