PluginProbe
Packeta / 2.1
Packeta v2.1
2.3.2 2.3.1 trunk 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.3.0 1.3.1 1.3.2 1.4 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 All 56 releases
packeta / src / Packetery / Module / Checkout / CurrencySwitcherService.php

CurrencySwitcherService.php in Packeta 2.1, at src/Packetery/Module/Checkout/CurrencySwitcherService.php

87 lines 1.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Class CurrencySwitcherService
4 *
5 * @package Packetery\Module
6 */
7
8 declare( strict_types=1 );
9
10 namespace Packetery\Module\Checkout;
11
12 use Packetery\Module\Framework\WpAdapter;
13 use Packetery\Module\ModuleHelper;
14
15 /**
16 * Class CurrencySwitcherService.
17 */
18 class CurrencySwitcherService {
19
20 /**
21 * @var WpAdapter
22 */
23 private $wpAdapter;
24
25 /**
26 * @var ModuleHelper
27 */
28 private $moduleHelper;
29
30 public function __construct(
31 WpAdapter $wpAdapter,
32 ModuleHelper $moduleHelper
33 ) {
34 $this->wpAdapter = $wpAdapter;
35 $this->moduleHelper = $moduleHelper;
36 }
37
38 /**
39 * List of supported plugins for options export.
40 *
41 * @var string[]
42 */
43 public static $supportedCurrencySwitchers = [
44 'WOOCS - WooCommerce Currency Switcher',
45 ];
46
47 /**
48 * Applies currency conversion if needed.
49 *
50 * @param float $price Price to convert.
51 *
52 * @return float
53 */
54 public function getConvertedPrice( float $price ): float {
55 if ( $this->moduleHelper->isPluginActive( 'woocommerce-currency-switcher/index.php' ) ) {
56 return $this->applyFilterWoocsExchangeValue( $price );
57 }
58
59 /**
60 * Applies packetery_price filters.
61 *
62 * @since 1.4
63 */
64 return (float) $this->wpAdapter->applyFilters( 'packetery_price', $price );
65 }
66
67 /**
68 * WooCommerce currency-switcher.com compatibility. Does no harm in case WOOCS is not active.
69 *
70 * @param float $value Value of the surcharge or transport price.
71 *
72 * @return float
73 */
74 private function applyFilterWoocsExchangeValue( float $value ): float {
75 if ( $value > 0 ) {
76 /**
77 * Applies woocs_exchange_value filters.
78 *
79 * @since 1.2.7
80 */
81 $value = (float) $this->wpAdapter->applyFilters( 'woocs_exchange_value', $value );
82 }
83
84 return $value;
85 }
86 }
87