| 1 |
<?php |
| 2 |
/** |
| 3 |
* Class CurrencySwitcherFacade |
| 4 |
* |
| 5 |
* @package Packetery\Module |
| 6 |
*/ |
| 7 |
|
| 8 |
declare( strict_types=1 ); |
| 9 |
|
| 10 |
namespace Packetery\Module; |
| 11 |
|
| 12 |
/** |
| 13 |
* Class CurrencySwitcherFacade. |
| 14 |
*/ |
| 15 |
class CurrencySwitcherFacade { |
| 16 |
|
| 17 |
/** |
| 18 |
* List of supported plugins for options export. |
| 19 |
* |
| 20 |
* @var string[] |
| 21 |
*/ |
| 22 |
public static $supportedCurrencySwitchers = [ |
| 23 |
'WOOCS - WooCommerce Currency Switcher', |
| 24 |
]; |
| 25 |
|
| 26 |
/** |
| 27 |
* Applies currency conversion if needed. |
| 28 |
* |
| 29 |
* @param float $price Price to convert. |
| 30 |
* |
| 31 |
* @return float |
| 32 |
*/ |
| 33 |
public function getConvertedPrice( float $price ): float { |
| 34 |
if ( Helper::isPluginActive( 'woocommerce-currency-switcher/index.php' ) ) { |
| 35 |
return $this->applyFilterWoocsExchangeValue( $price ); |
| 36 |
} |
| 37 |
|
| 38 |
/** |
| 39 |
* Applies packetery_price filters. |
| 40 |
* |
| 41 |
* @since 1.4 |
| 42 |
*/ |
| 43 |
return (float) apply_filters( 'packetery_price', $price ); |
| 44 |
} |
| 45 |
|
| 46 |
/** |
| 47 |
* WooCommerce currency-switcher.com compatibility. Does no harm in case WOOCS is not active. |
| 48 |
* |
| 49 |
* @param float $value Value of the surcharge or transport price. |
| 50 |
* |
| 51 |
* @return float |
| 52 |
*/ |
| 53 |
private function applyFilterWoocsExchangeValue( float $value ): float { |
| 54 |
if ( 0 < $value ) { |
| 55 |
/** |
| 56 |
* Applies woocs_exchange_value filters. |
| 57 |
* |
| 58 |
* @since 1.2.7 |
| 59 |
*/ |
| 60 |
$value = (float) apply_filters( 'woocs_exchange_value', $value ); |
| 61 |
} |
| 62 |
|
| 63 |
return $value; |
| 64 |
} |
| 65 |
} |
| 66 |
|