1 | <?php |
||
2 | /** |
||
3 | * LSX Currency Frontend Class |
||
4 | * |
||
5 | * @package LSX Currencies |
||
6 | * @author LightSpeed |
||
7 | * @license GPL3 |
||
8 | * @link |
||
9 | * @copyright 2019 LightSpeed |
||
10 | */ |
||
11 | |||
12 | namespace lsx\currencies\classes; |
||
13 | |||
14 | /** |
||
15 | * Holds the WooCommerce Integrations |
||
16 | */ |
||
17 | class WooCommerce { |
||
18 | |||
19 | /** |
||
20 | * Holds instance of the class |
||
21 | * |
||
22 | * @var object \lsx\currencies\classes\WooCommerce() |
||
23 | */ |
||
24 | private static $instance; |
||
25 | |||
26 | /** |
||
27 | * Holds the current currency. |
||
28 | * |
||
29 | * @var boolean |
||
30 | */ |
||
31 | public $currency = false; |
||
32 | |||
33 | /** |
||
34 | * Constructor |
||
35 | */ |
||
36 | public function __construct() { |
||
0 ignored issues
–
show
Coding Style
introduced
by
![]() |
|||
37 | add_filter( 'wc_price', array( $this, 'price_filter' ), 300, 3 ); |
||
38 | add_filter( 'lsx_currencies_base_currency', array( $this, 'set_base_currency' ), 10, 1 ); |
||
39 | } |
||
0 ignored issues
–
show
|
|||
40 | |||
41 | /** |
||
42 | * Return an instance of this class. |
||
43 | * |
||
44 | * @return object |
||
45 | */ |
||
46 | public static function init() { |
||
47 | // If the single instance hasn't been set, set it now. |
||
48 | if ( ! isset( self::$instance ) ) { |
||
0 ignored issues
–
show
|
|||
49 | self::$instance = new self(); |
||
50 | } |
||
0 ignored issues
–
show
|
|||
51 | return self::$instance; |
||
52 | } |
||
0 ignored issues
–
show
|
|||
53 | |||
54 | /** |
||
0 ignored issues
–
show
|
|||
55 | * Filter the WooCommerce Price. |
||
56 | * |
||
57 | * @param $return mixed |
||
0 ignored issues
–
show
|
|||
58 | * @param $price string |
||
0 ignored issues
–
show
|
|||
59 | * @param $args array |
||
0 ignored issues
–
show
|
|||
60 | * |
||
61 | * @return mixed |
||
62 | */ |
||
63 | public function price_filter( $return, $price, $args ) { |
||
64 | if ( '' !== $price ) { |
||
0 ignored issues
–
show
|
|||
65 | $return = str_replace( 'class', 'data-price-' . lsx_currencies()->base_currency . '=' . $price . ' class', $return ); |
||
66 | $return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return ); |
||
67 | } |
||
0 ignored issues
–
show
|
|||
68 | return $return; |
||
69 | } |
||
0 ignored issues
–
show
|
|||
70 | |||
71 | /** |
||
0 ignored issues
–
show
|
|||
72 | * @param $cart_subtotal |
||
0 ignored issues
–
show
|
|||
73 | * @param $compound |
||
0 ignored issues
–
show
|
|||
74 | * @param $obj |
||
0 ignored issues
–
show
|
|||
75 | * |
||
76 | * @return mixed |
||
77 | */ |
||
78 | public function cart_subtotal( $cart_subtotal, $compound, $obj ) { |
||
0 ignored issues
–
show
|
|||
79 | |||
80 | $return = str_replace( 'class', 'data-price-' . $this->currency . '=' . $price . ' class', $return ); |
||
81 | $return = str_replace( 'woocommerce-Price-amount', 'woocommerce-Price-amount lsx-currencies', $return ); |
||
82 | |||
83 | return $cart_subtotal; |
||
84 | } |
||
0 ignored issues
–
show
|
|||
85 | |||
86 | /** |
||
87 | * Make sure our base currency is set to the same as woocommerce. |
||
88 | * |
||
89 | * @param string $currency |
||
0 ignored issues
–
show
|
|||
90 | * @return void |
||
0 ignored issues
–
show
|
|||
91 | */ |
||
92 | public function set_base_currency( $currency ) { |
||
93 | return get_woocommerce_currency(); |
||
94 | } |
||
0 ignored issues
–
show
|
|||
95 | } |
||
96 |