Factory.php
2 weeks ago
Helper.php
2 weeks ago
MulticurrencyHooks.php
2 weeks ago
class-wcml-pip.php
2 years ago
MulticurrencyHooks.php
55 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WCML\Compatibility\WcPip; |
| 4 | |
| 5 | class MulticurrencyHooks implements \IWPML_Action { |
| 6 | |
| 7 | public function add_hooks() { |
| 8 | add_filter( 'woocommerce_currency_symbol', [ $this, 'filter_pip_currency_symbol' ] ); |
| 9 | add_filter( 'wcml_filter_currency_position', [ $this, 'filter_pip_currency_position' ] ); |
| 10 | } |
| 11 | |
| 12 | public function filter_pip_currency_symbol( $currencySymbol ) { |
| 13 | remove_filter( 'woocommerce_currency_symbol', [ $this, 'filter_pip_currency_symbol' ] ); |
| 14 | |
| 15 | $currency = self::getPipOrderCurrency(); |
| 16 | |
| 17 | if ( $currency ) { |
| 18 | $currencySymbol = get_woocommerce_currency_symbol( $currency ); |
| 19 | } |
| 20 | |
| 21 | add_filter( 'woocommerce_currency_symbol', [ $this, 'filter_pip_currency_symbol' ] ); |
| 22 | |
| 23 | return $currencySymbol; |
| 24 | } |
| 25 | |
| 26 | public function filter_pip_currency_position( $currency ) { |
| 27 | remove_filter( 'wcml_filter_currency_position', [ $this, 'filter_pip_currency_position' ] ); |
| 28 | |
| 29 | $currency = self::getPipOrderCurrency( $currency ); |
| 30 | |
| 31 | add_filter( 'wcml_filter_currency_position', [ $this, 'filter_pip_currency_position' ] ); |
| 32 | |
| 33 | return $currency; |
| 34 | } |
| 35 | |
| 36 | private static function getPipOrderCurrency( $currency = false ) { |
| 37 | $pip_order_id = Helper::getPipOrderId(); |
| 38 | |
| 39 | if ( $pip_order_id && WC()->order_factory instanceof \WC_Order_Factory ) { |
| 40 | |
| 41 | $the_order = WC()->order_factory->get_order( $pip_order_id ); |
| 42 | |
| 43 | if ( $the_order ) { |
| 44 | $currency = $the_order->get_currency(); |
| 45 | |
| 46 | if ( ! $currency && isset( $_COOKIE['_wcml_order_currency'] ) ) { |
| 47 | $currency = $_COOKIE['_wcml_order_currency']; |
| 48 | } |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | return $currency; |
| 53 | } |
| 54 | } |
| 55 |