| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPFunnels\Compatibility\Plugin; |
| 4 |
|
| 5 |
use WPFunnels\Traits\SingletonTrait; |
| 6 |
|
| 7 |
class FoxCurrencySwitcher extends PluginCompatibility{ |
| 8 |
use SingletonTrait; |
| 9 |
|
| 10 |
/** |
| 11 |
* Constructor: Initialize class and hook into price conversion. |
| 12 |
*/ |
| 13 |
public function init(){ |
| 14 |
add_filter('wpfunnels/modify_order_bump_price_on_main_order', array($this,'maybe_convert_product_price')); |
| 15 |
add_filter('wpfunnels/modify_order_bump_product_price', array($this, 'maybe_convert_order_bump_price')); |
| 16 |
} |
| 17 |
|
| 18 |
/** |
| 19 |
* Check if the Currency (WOOCS) is active. |
| 20 |
* |
| 21 |
* @return bool |
| 22 |
*/ |
| 23 |
public function maybe_activate(){ |
| 24 |
return class_exists('WOOCS'); |
| 25 |
} |
| 26 |
|
| 27 |
/** |
| 28 |
* Convert the price for the order bump using the current currency |
| 29 |
* |
| 30 |
* @param float $price |
| 31 |
* @return float Converted price |
| 32 |
*/ |
| 33 |
public function maybe_convert_product_price($price){ |
| 34 |
global $WOOCS; |
| 35 |
|
| 36 |
if ($this->maybe_activate()) { |
| 37 |
if ($WOOCS->is_multiple_allowed) { |
| 38 |
$current = $WOOCS->current_currency; |
| 39 |
if ($current != $WOOCS->default_currency) { |
| 40 |
$currencies = $WOOCS->get_currencies(); |
| 41 |
$rate = $currencies[$current]['rate']; |
| 42 |
$price = $price / $rate; |
| 43 |
} |
| 44 |
} |
| 45 |
} |
| 46 |
|
| 47 |
return $price; |
| 48 |
} |
| 49 |
|
| 50 |
public function maybe_convert_order_bump_price($price){ |
| 51 |
global $WOOCS; |
| 52 |
|
| 53 |
if ($this->maybe_activate()) { |
| 54 |
if ($WOOCS->is_multiple_allowed) { |
| 55 |
$price = $WOOCS->woocs_exchange_value(floatval($price)); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
return $price; |
| 60 |
} |
| 61 |
} |
| 62 |
|