class-wcml-currencies.php
41 lines
| 1 | <?php |
| 2 | |
| 3 | class WCML_Currencies { |
| 4 | |
| 5 | private $woocommerce_wpml; |
| 6 | |
| 7 | public function __construct( woocommerce_wpml $woocommerce_wpml ) { |
| 8 | $this->woocommerce_wpml = $woocommerce_wpml; |
| 9 | } |
| 10 | |
| 11 | public function add_hooks() { |
| 12 | if ( is_admin() ) { |
| 13 | add_action( |
| 14 | 'update_option_woocommerce_currency', |
| 15 | [ |
| 16 | $this, |
| 17 | 'setup_multi_currency_on_currency_update', |
| 18 | ], |
| 19 | 10, |
| 20 | 2 |
| 21 | ); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public function setup_multi_currency_on_currency_update( $old_value, $new_value ) { |
| 26 | if ( wcml_is_multi_currency_on() ) { |
| 27 | $multi_currency_install = new WCML_Multi_Currency_Install( new WCML_Multi_Currency(), $this->woocommerce_wpml ); |
| 28 | $multi_currency_install->set_default_currencies_languages( $old_value, $new_value ); |
| 29 | } else { |
| 30 | $currency_options = $this->woocommerce_wpml->get_setting( 'currency_options' ); |
| 31 | if ( isset( $currency_options[ $old_value ] ) ) { |
| 32 | $currency_options[ $new_value ] = $currency_options[ $old_value ]; |
| 33 | unset( $currency_options[ $old_value ] ); |
| 34 | $this->woocommerce_wpml->update_setting( 'currency_options', $currency_options ); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | } |
| 39 | |
| 40 | } |
| 41 |