WooCommerce Multilingual – run WooCommerce with WPML - Version 4.7.2

Version Description

Download this release

Release Info

Developer sergey.r
Plugin Icon 128x128 WooCommerce Multilingual – run WooCommerce with WPML
Version 4.7.2
Comparing to
See all releases

Code changes from version 4.7.1 to 4.7.2

changelog/4.7.1.md DELETED
@@ -1,3 +0,0 @@
1
- # Fixes
2
- * [wcml-2974] Fixed notice when id not set in order variable item data.
3
- * [wcml-2973] Fixed a fatal error when WooCommerce Multilingual is updated before WPML Translation Management.
 
 
 
changelog/4.7.2.md ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
1
+ # Fixes
2
+ * [wcml-2982] Fixed a fatal error that sometimes happened when updating WPML 4.1.0 to WPML 4.3.0.
3
+ * [wcml-2979] Fixed an error that happened when updating a product using the WooCommerce version older than 3.6.0.
4
+
5
+ # Performances
6
+ * [wcml-2980] Replaced the "wp_" cookie prefix with "wp-".
classes/product/class-wcml-product-data-store-cpt.php CHANGED
@@ -8,7 +8,9 @@ class WCML_Product_Data_Store_CPT extends WC_Product_Data_Store_CPT{
8
  * @param int $product_id
9
  */
10
  public function update_lookup_table_data( $product_id ){
11
- $this->update_lookup_table( $product_id, 'wc_product_meta_lookup' );
 
 
12
  }
13
 
14
  }
8
  * @param int $product_id
9
  */
10
  public function update_lookup_table_data( $product_id ){
11
+ if( method_exists( $this, 'update_lookup_table' ) ){
12
+ $this->update_lookup_table( $product_id, 'wc_product_meta_lookup' );
13
+ }
14
  }
15
 
16
  }
classes/shortcodes/class-wcml-wc-shortcode-product-category.php CHANGED
@@ -1,5 +1,7 @@
1
  <?php
2
 
 
 
3
  /**
4
  * Class WCML_WC_Shortcode_Product_Category
5
  * @since 4.2.2
@@ -38,9 +40,18 @@ class WCML_WC_Shortcode_Product_Category {
38
  if ( isset( $args['product_cat'] ) ) {
39
  $args = $this->translate_categories_using_simple_tax_query( $args );
40
  } elseif ( ! empty( $atts['category'] ) && isset( $args['tax_query'] ) ) {
41
- $categories = wpml_collect( explode(',', $atts['category'] ) )
42
- ->filter( 'trim' )
43
- ->map( function ( $category ) { return get_term( $category, 'product_cat' ); } );
 
 
 
 
 
 
 
 
 
44
 
45
  $args = $this->replace_category_in_query_arguments( $args, $categories );
46
  }
@@ -50,12 +61,12 @@ class WCML_WC_Shortcode_Product_Category {
50
  }
51
 
52
  /**
53
- * @param array $args
54
- * @param array $terms
55
  *
56
  * @return array
57
  */
58
- private function replace_category_in_query_arguments( $args, $terms ){
59
 
60
  foreach ( $args['tax_query'] as $i => $tax_query ) {
61
  $args['tax_query'][ $i ] = array();
@@ -64,7 +75,7 @@ class WCML_WC_Shortcode_Product_Category {
64
  }
65
  foreach ( $tax_query as $j => $condition ) {
66
  if ( 'product_cat' === $condition['taxonomy'] ) {
67
- $condition['terms'] = wp_list_pluck( $terms, $condition['field'] );
68
  }
69
  $args['tax_query'][ $i ][] = $condition;
70
  }
1
  <?php
2
 
3
+ use WPML\Collect\Support\Collection;
4
+
5
  /**
6
  * Class WCML_WC_Shortcode_Product_Category
7
  * @since 4.2.2
40
  if ( isset( $args['product_cat'] ) ) {
41
  $args = $this->translate_categories_using_simple_tax_query( $args );
42
  } elseif ( ! empty( $atts['category'] ) && isset( $args['tax_query'] ) ) {
43
+ $getProductCategoryObject = function ( $slugOrId ) {
44
+ if ( is_numeric( $slugOrId ) ) {
45
+ return get_term( $slugOrId, 'product_cat' );
46
+ }
47
+
48
+ return get_term_by( 'slug', $slugOrId, 'product_cat' );
49
+ };
50
+
51
+ $categories = wpml_collect( explode( ',', $atts['category'] ) )
52
+ ->map( function( $slugOrId ) { return trim( $slugOrId ); } )
53
+ ->filter()
54
+ ->map( $getProductCategoryObject );
55
 
56
  $args = $this->replace_category_in_query_arguments( $args, $categories );
57
  }
61
  }
62
 
63
  /**
64
+ * @param array $args
65
+ * @param Collection $terms
66
  *
67
  * @return array
68
  */
69
+ private function replace_category_in_query_arguments( array $args, Collection $terms ){
70
 
71
  foreach ( $args['tax_query'] as $i => $tax_query ) {
72
  $args['tax_query'][ $i ] = array();
75
  }
76
  foreach ( $tax_query as $j => $condition ) {
77
  if ( 'product_cat' === $condition['taxonomy'] ) {
78
+ $condition['terms'] = $terms->pluck( $condition['field'] )->toArray();
79
  }
80
  $args['tax_query'][ $i ][] = $condition;
81
  }
inc/class-wcml-ajax-setup.php CHANGED
@@ -1,7 +1,7 @@
1
  <?php
2
-
3
-
4
- class WCML_Ajax_Setup{
5
 
6
  /**
7
  * @var SitePress
@@ -13,19 +13,22 @@ class WCML_Ajax_Setup{
13
  $this->sitepress = $sitepress;
14
  }
15
 
16
- public function add_hooks(){
17
 
18
- add_action( 'init', array( $this, 'init' ) );
19
- add_action( 'wcml_localize_woocommerce_on_ajax', array( $this, 'wcml_localize_woocommerce_on_ajax' ) );
20
 
21
- //@deprecated 3.9 Use 'wcml_localize_woocommerce_on_ajax' instead
22
- add_action( 'localize_woocommerce_on_ajax', array( $this, 'localize_woocommerce_on_ajax' ) );
23
 
24
- add_action( 'woocommerce_ajax_get_endpoint', array( $this, 'add_language_to_endpoint' ) );
25
- }
26
 
27
  public function init() {
28
  if ( wpml_is_ajax() ) {
 
 
 
29
  do_action( 'wcml_localize_woocommerce_on_ajax' );
30
  }
31
 
@@ -50,22 +53,24 @@ class WCML_Ajax_Setup{
50
  public function wcml_localize_woocommerce_on_ajax() {
51
  $action = isset( $_POST['action'] ) ? filter_var( $_POST['action'], FILTER_SANITIZE_STRING ) : false;
52
  $is_ajax_action = $action
53
- && in_array( $action,
54
- array(
55
- 'wcml_product_data',
56
- 'wpml_translation_dialog_save_job',
57
- 'edit-theme-plugin-file',
58
- 'search-install-plugins'
59
- ),
60
- true );
 
 
61
  if ( $action && ( $is_ajax_action || ! apply_filters( 'wcml_is_localize_woocommerce_on_ajax', true, $action ) ) ) {
62
  return;
63
  }
64
 
65
- $current_language = $this->sitepress->get_current_language();
66
 
67
- $this->sitepress->switch_lang($current_language, true);
68
- }
69
 
70
  /**
71
  * @param $endpoint string
@@ -74,13 +79,13 @@ class WCML_Ajax_Setup{
74
  *
75
  * @return string
76
  */
77
- public function add_language_to_endpoint( $endpoint ){
78
 
79
  $is_per_domain = WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN === (int) $this->sitepress->get_setting( 'language_negotiation_type' );
80
- if( $is_per_domain && $this->sitepress->get_current_language() != $this->sitepress->get_default_language() ){
81
 
82
- $endpoint = add_query_arg('lang', $this->sitepress->get_current_language(), remove_query_arg( 'lang', $endpoint ) );
83
- $endpoint = urldecode($endpoint);
84
 
85
  }
86
 
@@ -89,11 +94,11 @@ class WCML_Ajax_Setup{
89
 
90
 
91
  /**
92
- * @deprecated 3.9
93
- */
94
- function localize_woocommerce_on_ajax(){
95
- $this->wcml_localize_woocommerce_on_ajax();
96
- }
97
-
98
-
99
- }
1
  <?php
2
+
3
+
4
+ class WCML_Ajax_Setup {
5
 
6
  /**
7
  * @var SitePress
13
  $this->sitepress = $sitepress;
14
  }
15
 
16
+ public function add_hooks() {
17
 
18
+ add_action( 'init', [ $this, 'init' ] );
19
+ add_action( 'wcml_localize_woocommerce_on_ajax', [ $this, 'wcml_localize_woocommerce_on_ajax' ] );
20
 
21
+ // @deprecated 3.9 Use 'wcml_localize_woocommerce_on_ajax' instead
22
+ add_action( 'localize_woocommerce_on_ajax', [ $this, 'localize_woocommerce_on_ajax' ] );
23
 
24
+ add_action( 'woocommerce_ajax_get_endpoint', [ $this, 'add_language_to_endpoint' ] );
25
+ }
26
 
27
  public function init() {
28
  if ( wpml_is_ajax() ) {
29
+ /**
30
+ * @since 3.9.0
31
+ */
32
  do_action( 'wcml_localize_woocommerce_on_ajax' );
33
  }
34
 
53
  public function wcml_localize_woocommerce_on_ajax() {
54
  $action = isset( $_POST['action'] ) ? filter_var( $_POST['action'], FILTER_SANITIZE_STRING ) : false;
55
  $is_ajax_action = $action
56
+ && in_array(
57
+ $action,
58
+ [
59
+ 'wcml_product_data',
60
+ 'wpml_translation_dialog_save_job',
61
+ 'edit-theme-plugin-file',
62
+ 'search-install-plugins',
63
+ ],
64
+ true
65
+ );
66
  if ( $action && ( $is_ajax_action || ! apply_filters( 'wcml_is_localize_woocommerce_on_ajax', true, $action ) ) ) {
67
  return;
68
  }
69
 
70
+ $current_language = $this->sitepress->get_current_language();
71
 
72
+ $this->sitepress->switch_lang( $current_language, true );
73
+ }
74
 
75
  /**
76
  * @param $endpoint string
79
  *
80
  * @return string
81
  */
82
+ public function add_language_to_endpoint( $endpoint ) {
83
 
84
  $is_per_domain = WPML_LANGUAGE_NEGOTIATION_TYPE_DOMAIN === (int) $this->sitepress->get_setting( 'language_negotiation_type' );
85
+ if ( $is_per_domain && $this->sitepress->get_current_language() != $this->sitepress->get_default_language() ) {
86
 
87
+ $endpoint = add_query_arg( 'lang', $this->sitepress->get_current_language(), remove_query_arg( 'lang', $endpoint ) );
88
+ $endpoint = urldecode( $endpoint );
89
 
90
  }
91
 
94
 
95
 
96
  /**
97
+ * @deprecated 3.9
98
+ */
99
+ function localize_woocommerce_on_ajax() {
100
+ $this->wcml_localize_woocommerce_on_ajax();
101
+ }
102
+
103
+
104
+ }
inc/class-wcml-endpoints.php CHANGED
@@ -85,7 +85,7 @@ class WCML_Endpoints {
85
  icl_add_string_translation( $existing_string_id, $language_code, $translation_data['value'], ICL_STRING_TRANSLATION_COMPLETE );
86
  }
87
 
88
- wpml_unregister_string_multi( $existing_wcml_string_id );
89
  }
90
  }else{
91
 
85
  icl_add_string_translation( $existing_string_id, $language_code, $translation_data['value'], ICL_STRING_TRANSLATION_COMPLETE );
86
  }
87
 
88
+ wpml_unregister_string_multi( [ $existing_wcml_string_id ] );
89
  }
90
  }else{
91
 
inc/class-wcml-wc-shipping.php CHANGED
@@ -99,6 +99,9 @@ class WCML_WC_Shipping{
99
  function translate_shipping_methods_in_package( $available_methods ){
100
 
101
  foreach($available_methods as $key => $method){
 
 
 
102
  if( apply_filters( 'wcml_translate_shipping_method_in_package', true, $key, $method ) ){
103
  $available_methods[$key]->label = $this->translate_shipping_method_title( $method->label, $key );
104
  }
@@ -266,4 +269,4 @@ class WCML_WC_Shipping{
266
  return $rate;
267
  }
268
 
269
- }
99
  function translate_shipping_methods_in_package( $available_methods ){
100
 
101
  foreach($available_methods as $key => $method){
102
+ /**
103
+ * @since 4.6.5
104
+ */
105
  if( apply_filters( 'wcml_translate_shipping_method_in_package', true, $key, $method ) ){
106
  $available_methods[$key]->label = $this->translate_shipping_method_title( $method->label, $key );
107
  }
269
  return $rate;
270
  }
271
 
272
+ }
inc/currencies/class-wcml-multi-currency.php CHANGED
@@ -3,518 +3,514 @@
3
  // Our case:
4
  // Muli-currency can be enabled by an option in wp_options - wcml_multi_currency_enabled
5
  // User currency will be set in the woocommerce session as 'client_currency'
6
- //
7
-
8
- class WCML_Multi_Currency{
9
-
10
- /** @var array */
11
- public $currencies = array();
12
- /** @var array */
13
- public $currency_codes = array();
14
-
15
- /** @var string */
16
- private $default_currency;
17
- /** @var string */
18
- private $client_currency;
19
- /** @var array */
20
- private $exchange_rates = array();
21
- /** @var array */
22
- public $currencies_without_cents = array('JPY', 'TWD', 'KRW', 'BIF', 'BYR', 'CLP', 'GNF', 'ISK', 'KMF', 'PYG', 'RWF', 'VUV', 'XAF', 'XOF', 'XPF');
23
-
24
- /**
25
- * @var WCML_Multi_Currency_Prices
26
- */
27
- public $prices;
28
- /**
29
- * @var WCML_Multi_Currency_Coupons
30
- */
31
- public $coupons;
32
- /**
33
- * @var WCML_Multi_Currency_Shipping
34
- */
35
- public $shipping;
36
-
37
- /**
38
- * @var WCML_Multi_Currency_Reports
39
- */
40
- public $reports;
41
- /**
42
- * @var WCML_Multi_Currency_Orders
43
- */
44
- public $orders;
45
- /**
46
- * @var WCML_Admin_Currency_Selector
47
- */
48
- public $admin_currency_selector;
49
- /**
50
- * @var WCML_Custom_Prices
51
- */
52
- public $custom_prices;
53
- /**
54
- * @var WCML_Currency_Switcher
55
- */
56
- public $currency_switcher;
57
- /**
58
- * @var WCML_Currency_Switcher_Ajax
59
- */
60
- public $currency_switcher_ajax;
61
  /**
62
  * @var WCML_Multi_Currency_Install
63
  */
64
  public $install;
65
 
66
- public $W3TC = false;
67
-
68
- /**
69
- * @var woocommerce_wpml
70
- */
71
- public $woocommerce_wpml;
72
-
73
- /**
74
- * @var WCML_Exchange_Rate_Service
75
- */
76
- public $exchange_rate_services;
77
-
78
- /**
79
- * @var WCML_Currencies_Payment_Gateways
80
- */
81
- public $currencies_payment_gateways;
82
-
83
- /**
84
- * @var bool
85
- */
86
- public $load_filters;
87
-
88
- /**
89
- * @var string
90
- */
91
- public $switching_currency_html;
92
-
93
-
94
- /**
95
- * WCML_Multi_Currency constructor.
96
- */
97
- public function __construct(){
98
- global $woocommerce_wpml, $sitepress, $wpdb, $wp_locale, $wp;
99
-
100
- $this->woocommerce_wpml =& $woocommerce_wpml;
101
-
102
- $this->install = new WCML_Multi_Currency_Install( $this, $woocommerce_wpml );
103
-
104
- $this->init_currencies();
105
-
106
- $this->load_filters = $this->_load_filters();
107
- $this->prices = new WCML_Multi_Currency_Prices( $this );
108
- $this->prices->add_hooks();
109
- if( $this->load_filters ) {
110
- $table_rate_shipping_multi_currency = new WCML_Multi_Currency_Table_Rate_Shipping();
111
- $table_rate_shipping_multi_currency->add_hooks();
112
-
113
- $this->coupons = new WCML_Multi_Currency_Coupons();
114
- $this->shipping = new WCML_Multi_Currency_Shipping( $this, $sitepress, $wpdb );
115
- $this->shipping->add_hooks();
116
- }
117
- $this->reports = new WCML_Multi_Currency_Reports( $woocommerce_wpml, $sitepress, $wpdb );
118
- $this->reports->add_hooks();
119
- $this->orders = new WCML_Multi_Currency_Orders( $this, $woocommerce_wpml, $wp );
120
- $this->admin_currency_selector = new WCML_Admin_Currency_Selector(
121
- $woocommerce_wpml,
122
- new WCML_Admin_Cookie( '_wcml_dashboard_currency' )
123
- );
124
- $this->admin_currency_selector->add_hooks();
125
- $this->custom_prices = new WCML_Custom_Prices( $woocommerce_wpml, $wpdb );
126
- $this->custom_prices->add_hooks();
127
- $this->currency_switcher = new WCML_Currency_Switcher( $woocommerce_wpml, $sitepress );
128
- $this->currency_switcher->add_hooks();
129
- $this->currency_switcher_ajax = new WCML_Currency_Switcher_Ajax( $woocommerce_wpml );
130
-
131
- $this->exchange_rate_services = new WCML_Exchange_Rates( $this->woocommerce_wpml, $wp_locale );
132
- $this->exchange_rate_services->initialize_settings();
133
- $this->exchange_rate_services->add_actions();
134
- $this->exchange_rate_services->add_service( 'fixerio', new WCML_Exchange_Rates_Fixerio() );
135
- $this->exchange_rate_services->add_service( 'currencylayer', new WCML_Exchange_Rates_Currencylayer() );
136
-
137
- $this->currencies_payment_gateways = new WCML_Currencies_Payment_Gateways( $this->woocommerce_wpml, $sitepress->get_wp_api() );
138
- $this->currencies_payment_gateways->add_hooks();
139
-
140
- if( defined('W3TC') ){
141
- $this->W3TC = new WCML_W3TC_Multi_Currency();
142
- }
143
-
144
- WCML_Multi_Currency_Resources::set_up( $this, $this->woocommerce_wpml );
145
- WCML_Multi_Currency_Configuration::set_up( $this, $woocommerce_wpml );
146
-
147
- add_filter('init', array($this, 'init'), 5);
148
-
149
- if( is_ajax() ){
150
- add_action('wp_ajax_nopriv_wcml_switch_currency', array($this, 'switch_currency'));
151
- add_action('wp_ajax_wcml_switch_currency', array($this, 'switch_currency'));
152
- }
153
-
154
- }
155
-
156
- private function _load_filters(){
157
- $load = false;
158
-
159
- if(!is_admin() && $this->get_client_currency() !== wcml_get_woocommerce_currency_option() ){
160
- $load = true;
161
- }else{
162
- if(is_ajax() && $this->get_client_currency() !== wcml_get_woocommerce_currency_option() ){
163
-
164
- $ajax_actions = apply_filters( 'wcml_multi_currency_ajax_actions',
165
- array(
166
- 'woocommerce_get_refreshed_fragments',
167
- 'woocommerce_update_order_review',
168
- 'woocommerce-checkout',
169
- 'woocommerce_checkout',
170
- 'woocommerce_add_to_cart',
171
- 'woocommerce_update_shipping_method',
172
- 'woocommerce_json_search_products_and_variations',
173
- 'woocommerce_add_coupon_discount',
174
-
175
- )
176
- );
177
-
178
- if( ( isset( $_POST['action'] ) && in_array( $_POST['action'], $ajax_actions ) ) ||
179
- ( isset( $_GET['action'] ) && in_array( $_GET['action'], $ajax_actions ) ) ){
180
- $load = true;
181
- }
182
-
183
- }
184
- }
185
-
186
- /**
187
- * @deprecated 3.9.2
188
- */
189
- $load = apply_filters( 'wcml_load_multi_currency', $load );
190
-
191
- $load = apply_filters( 'wcml_load_multi_currency_in_ajax', $load );
192
-
193
- return $load;
194
- }
195
-
196
- public function init() {
197
-
198
- add_filter( 'wcml_get_client_currency', array($this, 'get_client_currency') );
199
- add_action( 'wp_footer', array( $this, 'maybe_show_switching_currency_prompt_dialog' ) );
200
- add_action( 'wp_footer', array( $this, 'maybe_reset_cart_fragments' ) );
201
-
202
- }
203
-
204
- public function enable(){
205
- $this->woocommerce_wpml->settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_INDEPENDENT;
206
- $this->woocommerce_wpml->update_settings();
207
- }
208
-
209
- public function disable(){
210
- $this->woocommerce_wpml->settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_DISABLED;
211
- $this->woocommerce_wpml->update_settings();
212
- }
213
-
214
- public function init_currencies(){
215
- global $sitepress;
216
-
217
- $this->default_currency = wcml_get_woocommerce_currency_option();
218
- $this->currencies =& $this->woocommerce_wpml->settings['currency_options'];
219
-
220
- // Add default currency if missing (set when MC is off)
221
- if( !empty( $this->default_currency ) && !isset( $this->currencies[ $this->default_currency ] ) ){
222
- $this->currencies[ $this->default_currency ] = array();
223
- }
224
-
225
- $save_to_db = false;
226
-
227
- $active_languages = $sitepress->get_active_languages();
228
-
229
- $currency_defaults = array(
230
- 'rate' => 0,
231
- 'position' => 'left',
232
- 'thousand_sep' => ',',
233
- 'decimal_sep' => '.',
234
- 'num_decimals' => 2,
235
- 'rounding' => 'disabled',
236
- 'rounding_increment' => 1,
237
- 'auto_subtract' => 0
238
- );
239
-
240
- foreach($this->currencies as $code => $currency){
241
- foreach($currency_defaults as $key => $val){
242
- if(!isset($currency[$key])){
243
- $this->currencies[$code][$key] = $val;
244
- $save_to_db = true;
245
- }
246
- }
247
-
248
- foreach($active_languages as $language){
249
- if(!isset($currency['languages'][$language['code']])){
250
- $this->currencies[$code]['languages'][$language['code']] = 1;
251
- $save_to_db = true;
252
- }
253
- }
254
- }
255
-
256
- $this->currency_codes = array_keys($this->currencies);
257
-
258
- // default language currencies
259
- foreach($active_languages as $language){
260
- if(!isset($this->woocommerce_wpml->settings['default_currencies'][$language['code']])){
261
- $this->woocommerce_wpml->settings['default_currencies'][$language['code']] = 0;
262
- $save_to_db = true;
263
- }
264
- }
265
-
266
- // sanity check
267
- if(isset($this->woocommerce_wpml->settings['default_currencies'])){
268
- foreach($this->woocommerce_wpml->settings['default_currencies'] as $language => $value){
269
- if(!isset($active_languages[$language])){
270
- unset($this->woocommerce_wpml->settings['default_currencies'][$language]);
271
- $save_to_db = true;
272
- }
273
- if(!empty($value) && !in_array($value, $this->currency_codes)){
274
- $this->woocommerce_wpml->settings['default_currencies'][$language] = 0;
275
- $save_to_db = true;
276
- }
277
- }
278
- }
279
-
280
- // add missing currencies to currencies_order
281
- if(isset($this->woocommerce_wpml->settings['currencies_order'])){
282
- foreach ($this->currency_codes as $currency) {
283
- if (!in_array($currency, $this->woocommerce_wpml->settings['currencies_order'])) {
284
- $this->woocommerce_wpml->settings['currencies_order'][] = $currency;
285
- $save_to_db = true;
286
- }
287
- }
288
- }
289
-
290
- if($save_to_db){
291
- $this->woocommerce_wpml->update_settings();
292
- }
293
-
294
- // force disable multi-currency when the default currency is empty
295
- if( empty( $this->default_currency ) ){
296
- $this->woocommerce_wpml->settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_DISABLED;
297
- }
298
-
299
- }
300
-
301
- /**
302
- *
303
- * @since 3.9.2
304
- * @return string
305
- */
306
- public function get_default_currency(){
307
- return $this->default_currency;
308
- }
309
-
310
- public function get_currencies( $include_default = false ){
311
-
312
- // by default, exclude default currency
313
- $currencies = array();
314
- $default_currency = wcml_get_woocommerce_currency_option();
315
-
316
- foreach($this->currencies as $key => $value){
317
- if( $default_currency != $key || $include_default ){
318
- $currencies[$key] = $value;
319
- }
320
- }
321
-
322
- return $currencies;
323
- }
324
-
325
- public function get_currency_codes(){
326
- return $this->currency_codes;
327
- }
328
-
329
- public function get_currency_details_by_code( $code ){
330
-
331
- if( isset( $this->currencies[ $code ] ) ){
332
- return $this->currencies[ $code ] ;
333
- }
334
-
335
- return false;
336
- }
337
-
338
- public function delete_currency_by_code( $code, $settings = false, $update = true ){
339
- $settings = $settings ? $settings : $this->woocommerce_wpml->get_settings();
340
- unset( $settings[ 'currency_options' ][ $code ] );
341
-
342
- if( isset( $settings[ 'currencies_order' ] ) ){
343
- foreach( $settings[ 'currencies_order' ] as $key => $cur_code ){
344
- if( $cur_code == $code ) {
345
- unset( $settings[ 'currencies_order' ][ $key ] );
346
- }
347
- }
348
- }
349
-
350
- if( $update ){
351
- $this->woocommerce_wpml->update_settings( $settings );
352
- }
353
-
354
- return $settings;
355
- }
356
-
357
- public function get_exchange_rates(){
358
-
359
- if(empty($this->exchange_rates)){
360
-
361
- $this->exchange_rates = array( wcml_get_woocommerce_currency_option() => 1);
362
- $woo_currencies = get_woocommerce_currencies();
363
-
364
- $currencies = $this->get_currencies();
365
- foreach($currencies as $code => $currency){
366
- if(!empty($woo_currencies[$code])){
367
- $this->exchange_rates[$code] = $currency['rate'];
368
- }
369
- }
370
- }
371
-
372
- return apply_filters('wcml_exchange_rates', $this->exchange_rates);
373
- }
374
-
375
- public function get_client_currency(){
376
- global $woocommerce, $sitepress, $wpdb;
377
-
378
- $WCML_REST_API = new WCML_REST_API();
379
- if(
380
- $WCML_REST_API->is_rest_api_request() ||
381
- ! empty( $_REQUEST['woocommerce_quick_edit'] )
382
- ){
383
- return wcml_get_woocommerce_currency_option();
384
- }
385
-
386
- $default_currencies = $this->woocommerce_wpml->settings['default_currencies'];
387
- $current_language = $sitepress->get_current_language();
388
- $current_language = ( $current_language != 'all' && !is_null( $current_language ) ) ? $current_language : $sitepress->get_default_language();
389
-
390
- if( !$this->client_currency &&
391
- isset($this->woocommerce_wpml->settings['display_custom_prices']) &&
392
- $this->woocommerce_wpml->settings['display_custom_prices'] &&
393
- is_product()
394
- ){
395
-
396
- $product_obj = wc_get_product();
397
- $current_product_id = get_post()->ID;
398
- $original_product_language = $this->woocommerce_wpml->products->get_original_product_language( $current_product_id );
399
- $default = false;
400
-
401
- if( $product_obj->get_type() === 'variable' ){
402
- foreach( $product_obj->get_children() as $child ){
403
- if( !get_post_meta( apply_filters( 'translate_object_id', $child , get_post_type( $child ), true, $original_product_language ), '_wcml_custom_prices_status', true ) ){
404
- $default = true;
405
- break;
406
- }
407
- }
408
- }elseif( !get_post_meta( apply_filters( 'translate_object_id', $current_product_id , get_post_type( $current_product_id ), true, $original_product_language ), '_wcml_custom_prices_status', true ) ){
409
- $default = true;
410
- }
411
-
412
- if( $default ){
413
- $this->client_currency = wcml_get_woocommerce_currency_option();
414
- }
415
-
416
-
417
- }
418
-
419
- if( isset($_GET['pay_for_order']) && $_GET['pay_for_order'] == true && isset($_GET['key']) ){
420
- $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_order_key' AND meta_value = %s", sanitize_text_field( $_GET['key'] ) ) );
421
- if( $order_id ){
422
- $this->client_currency = get_post_meta( $order_id, '_order_currency', true );
423
- }
424
-
425
- }
426
-
427
- if(
428
- isset( $_POST[ 'action' ] ) &&
429
- $_POST[ 'action' ] == 'wcml_switch_currency' &&
430
- !empty( $_POST[ 'currency' ] ) &&
431
- isset( $_POST[ 'force_switch' ] ) &&
432
- !$_POST[ 'force_switch' ] &&
433
- (
434
- $this->woocommerce_wpml->settings[ 'cart_sync' ][ 'currency_switch' ] == WCML_CART_SYNC ||
435
- $this->woocommerce_wpml->settings[ 'cart_sync' ][ 'currency_switch' ] == WCML_CART_SYNC
436
- )
437
- ){
438
- $this->client_currency = filter_input( INPUT_POST, 'currency', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
439
- }
440
-
441
- if( isset( $_GET['action'] ) &&
442
- $_GET['action'] === 'woocommerce_json_search_products_and_variations' &&
443
- !empty( $_COOKIE['_wcml_order_currency'] ) ) {
444
- $this->client_currency = $_COOKIE['_wcml_order_currency'];
445
- }
446
-
447
- if( is_null($this->client_currency) &&
448
- isset($default_currencies[$current_language]) &&
449
- $default_currencies[$current_language] &&
450
- !empty($woocommerce->session) &&
451
- $current_language != $woocommerce->session->get('client_currency_language') )
452
- {
453
-
454
- $current_currency = $woocommerce->session->get('client_currency');
455
- $client_currency = $default_currencies[ $current_language ];
456
- $prevent_switching = apply_filters( 'wcml_switch_currency_exception', false, $current_currency, $client_currency, true );
457
-
458
- $this->client_currency = $client_currency;
459
- if ( ! array_key_exists( 'force_switch', $_POST ) && $prevent_switching ) {
460
- $this->switching_currency_html = $prevent_switching['prevent_switching'];
461
- }
462
-
463
- }
464
-
465
- //edit order page
466
- if( isset( $_SERVER[ 'HTTP_REFERER' ] ) ){
467
- $arg = parse_url( $_SERVER[ 'HTTP_REFERER' ] );
468
- if( isset( $arg[ 'query' ] ) ){
469
- parse_str( $arg[ 'query' ], $arg );
470
- if( isset( $arg[ 'post' ] ) && get_post_type( $arg[ 'post' ] ) == 'shop_order' ){
471
- $this->client_currency = get_post_meta( $arg[ 'post' ], '_order_currency', true );
472
- }
473
- }
474
- }
475
-
476
- // client currency in general / if enabled for this language
477
- if( is_null( $this->client_currency ) && !empty( $woocommerce->session ) ){
478
- $session_currency = $woocommerce->session->get('client_currency');
479
- if($session_currency && !empty($this->currencies[$session_currency]['languages'][$current_language])){
480
-
481
- $this->client_currency = $woocommerce->session->get('client_currency');
482
- }
483
-
484
- }
485
-
486
- if( is_null( $this->client_currency ) ){
487
- $woocommerce_currency = wcml_get_woocommerce_currency_option();
488
-
489
- // fall on WC currency if enabled for this language
490
- if(!empty($this->currencies[$woocommerce_currency]['languages'][$current_language])){
491
- $this->client_currency = $woocommerce_currency;
492
- }else{
493
- // first currency enabled for this language
494
- foreach($this->currencies as $code => $data){
495
- if(!empty($data['languages'][$current_language])){
496
- $this->client_currency = $code;
497
- break;
498
- }
499
- }
500
- }
501
- }
502
-
503
- $this->client_currency = apply_filters( 'wcml_client_currency', $this->client_currency );
504
-
505
- if(!empty($woocommerce->session) && $this->client_currency){
506
- $woocommerce->session->set('client_currency', $this->client_currency);
507
- $woocommerce->session->set('client_currency_language',$current_language);
508
- }
509
-
510
- return $this->client_currency;
511
- }
512
-
513
- public function maybe_show_switching_currency_prompt_dialog(){
514
- if( $this->switching_currency_html ){
515
- echo $this->switching_currency_html;
516
- }
517
- }
518
 
519
  public function maybe_reset_cart_fragments() {
520
  global $woocommerce;
@@ -522,9 +518,9 @@ class WCML_Multi_Currency{
522
  if ( ! empty( $woocommerce->session ) && $woocommerce->session->get( 'client_currency_switched' ) ) {
523
  ?>
524
  <script type="text/javascript">
525
- jQuery(document).ready(function () {
526
- wcml_reset_cart_fragments();
527
- });
528
  </script>
529
  <?php
530
  $woocommerce->session->set( 'client_currency_switched', false );
@@ -532,50 +528,50 @@ class WCML_Multi_Currency{
532
 
533
  }
534
 
535
- public function set_client_currency($currency){
536
- global $woocommerce,$sitepress;
537
 
538
- $this->client_currency = $currency;
539
 
540
- $woocommerce->session->set('client_currency', $currency);
541
- $woocommerce->session->set('client_currency_language', $sitepress->get_current_language());
542
 
 
543
 
544
- do_action('wcml_set_client_currency', $currency);
545
 
546
- }
547
 
548
- public function switch_currency(){
 
549
 
550
- $currency = filter_input( INPUT_POST, 'currency', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
551
- $force_switch = filter_input( INPUT_POST, 'force_switch', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
552
 
553
- do_action( 'wcml_before_switch_currency', $currency, $force_switch );
 
 
554
 
555
- if( !$force_switch && apply_filters( 'wcml_switch_currency_exception', false, $this->client_currency, $currency ) ){
556
- die();
557
- }
558
 
559
- $this->set_client_currency($currency, $force_switch);
 
 
 
 
560
 
561
- // force set user cookie when user is not logged in
562
- global $woocommerce, $current_user;
563
- if(empty($woocommerce->session->data) && empty($current_user->ID)){
564
- $woocommerce->session->set_customer_session_cookie(true);
565
- }
566
 
567
- $woocommerce->session->set('client_currency_switched', true );
568
 
569
- do_action('wcml_switch_currency', $currency );
 
570
 
571
- echo json_encode( array() );
572
- die();
573
 
574
- }
575
 
576
- public function get_currencies_without_cents(){
 
577
 
578
- return apply_filters( 'wcml_currencies_without_cents', $this->currencies_without_cents );
579
- }
580
 
581
- }
3
  // Our case:
4
  // Muli-currency can be enabled by an option in wp_options - wcml_multi_currency_enabled
5
  // User currency will be set in the woocommerce session as 'client_currency'
6
+ //
7
+ class WCML_Multi_Currency {
8
+
9
+ /** @var array */
10
+ public $currencies = [];
11
+ /** @var array */
12
+ public $currency_codes = [];
13
+
14
+ /** @var string */
15
+ private $default_currency;
16
+ /** @var string */
17
+ private $client_currency;
18
+ /** @var array */
19
+ private $exchange_rates = [];
20
+ /** @var array */
21
+ public $currencies_without_cents = [ 'JPY', 'TWD', 'KRW', 'BIF', 'BYR', 'CLP', 'GNF', 'ISK', 'KMF', 'PYG', 'RWF', 'VUV', 'XAF', 'XOF', 'XPF' ];
22
+
23
+ /**
24
+ * @var WCML_Multi_Currency_Prices
25
+ */
26
+ public $prices;
27
+ /**
28
+ * @var WCML_Multi_Currency_Coupons
29
+ */
30
+ public $coupons;
31
+ /**
32
+ * @var WCML_Multi_Currency_Shipping
33
+ */
34
+ public $shipping;
35
+
36
+ /**
37
+ * @var WCML_Multi_Currency_Reports
38
+ */
39
+ public $reports;
40
+ /**
41
+ * @var WCML_Multi_Currency_Orders
42
+ */
43
+ public $orders;
44
+ /**
45
+ * @var WCML_Admin_Currency_Selector
46
+ */
47
+ public $admin_currency_selector;
48
+ /**
49
+ * @var WCML_Custom_Prices
50
+ */
51
+ public $custom_prices;
52
+ /**
53
+ * @var WCML_Currency_Switcher
54
+ */
55
+ public $currency_switcher;
56
+ /**
57
+ * @var WCML_Currency_Switcher_Ajax
58
+ */
59
+ public $currency_switcher_ajax;
 
60
  /**
61
  * @var WCML_Multi_Currency_Install
62
  */
63
  public $install;
64
 
65
+ public $W3TC = false;
66
+
67
+ /**
68
+ * @var woocommerce_wpml
69
+ */
70
+ public $woocommerce_wpml;
71
+
72
+ /**
73
+ * @var WCML_Exchange_Rate_Service
74
+ */
75
+ public $exchange_rate_services;
76
+
77
+ /**
78
+ * @var WCML_Currencies_Payment_Gateways
79
+ */
80
+ public $currencies_payment_gateways;
81
+
82
+ /**
83
+ * @var bool
84
+ */
85
+ public $load_filters;
86
+
87
+ /**
88
+ * @var string
89
+ */
90
+ public $switching_currency_html;
91
+
92
+
93
+ /**
94
+ * WCML_Multi_Currency constructor.
95
+ */
96
+ public function __construct() {
97
+ global $woocommerce_wpml, $sitepress, $wpdb, $wp_locale, $wp;
98
+
99
+ $this->woocommerce_wpml =& $woocommerce_wpml;
100
+
101
+ $this->install = new WCML_Multi_Currency_Install( $this, $woocommerce_wpml );
102
+
103
+ $this->init_currencies();
104
+
105
+ $this->load_filters = $this->_load_filters();
106
+ $this->prices = new WCML_Multi_Currency_Prices( $this );
107
+ $this->prices->add_hooks();
108
+ if ( $this->load_filters ) {
109
+ $table_rate_shipping_multi_currency = new WCML_Multi_Currency_Table_Rate_Shipping();
110
+ $table_rate_shipping_multi_currency->add_hooks();
111
+
112
+ $this->coupons = new WCML_Multi_Currency_Coupons();
113
+ $this->shipping = new WCML_Multi_Currency_Shipping( $this, $sitepress, $wpdb );
114
+ $this->shipping->add_hooks();
115
+ }
116
+ $this->reports = new WCML_Multi_Currency_Reports( $woocommerce_wpml, $sitepress, $wpdb );
117
+ $this->reports->add_hooks();
118
+ $this->orders = new WCML_Multi_Currency_Orders( $this, $woocommerce_wpml, $wp );
119
+ $this->admin_currency_selector = new WCML_Admin_Currency_Selector(
120
+ $woocommerce_wpml,
121
+ new WCML_Admin_Cookie( '_wcml_dashboard_currency' )
122
+ );
123
+ $this->admin_currency_selector->add_hooks();
124
+ $this->custom_prices = new WCML_Custom_Prices( $woocommerce_wpml, $wpdb );
125
+ $this->custom_prices->add_hooks();
126
+ $this->currency_switcher = new WCML_Currency_Switcher( $woocommerce_wpml, $sitepress );
127
+ $this->currency_switcher->add_hooks();
128
+ $this->currency_switcher_ajax = new WCML_Currency_Switcher_Ajax( $woocommerce_wpml );
129
+
130
+ $this->exchange_rate_services = new WCML_Exchange_Rates( $this->woocommerce_wpml, $wp_locale );
131
+ $this->exchange_rate_services->initialize_settings();
132
+ $this->exchange_rate_services->add_actions();
133
+ $this->exchange_rate_services->add_service( 'fixerio', new WCML_Exchange_Rates_Fixerio() );
134
+ $this->exchange_rate_services->add_service( 'currencylayer', new WCML_Exchange_Rates_Currencylayer() );
135
+
136
+ $this->currencies_payment_gateways = new WCML_Currencies_Payment_Gateways( $this->woocommerce_wpml, $sitepress->get_wp_api() );
137
+ $this->currencies_payment_gateways->add_hooks();
138
+
139
+ if ( defined( 'W3TC' ) ) {
140
+ $this->W3TC = new WCML_W3TC_Multi_Currency();
141
+ }
142
+
143
+ WCML_Multi_Currency_Resources::set_up( $this, $this->woocommerce_wpml );
144
+ WCML_Multi_Currency_Configuration::set_up( $this, $woocommerce_wpml );
145
+
146
+ add_filter( 'init', [ $this, 'init' ], 5 );
147
+
148
+ if ( is_ajax() ) {
149
+ add_action( 'wp_ajax_nopriv_wcml_switch_currency', [ $this, 'switch_currency' ] );
150
+ add_action( 'wp_ajax_wcml_switch_currency', [ $this, 'switch_currency' ] );
151
+ }
152
+
153
+ }
154
+
155
+ private function _load_filters() {
156
+ $load = false;
157
+
158
+ if ( ! is_admin() && $this->get_client_currency() !== wcml_get_woocommerce_currency_option() ) {
159
+ $load = true;
160
+ } else {
161
+ if ( is_ajax() && $this->get_client_currency() !== wcml_get_woocommerce_currency_option() ) {
162
+
163
+ $ajax_actions = apply_filters(
164
+ 'wcml_multi_currency_ajax_actions',
165
+ [
166
+ 'woocommerce_get_refreshed_fragments',
167
+ 'woocommerce_update_order_review',
168
+ 'woocommerce-checkout',
169
+ 'woocommerce_checkout',
170
+ 'woocommerce_add_to_cart',
171
+ 'woocommerce_update_shipping_method',
172
+ 'woocommerce_json_search_products_and_variations',
173
+ 'woocommerce_add_coupon_discount',
174
+
175
+ ]
176
+ );
177
+
178
+ if ( ( isset( $_POST['action'] ) && in_array( $_POST['action'], $ajax_actions ) ) ||
179
+ ( isset( $_GET['action'] ) && in_array( $_GET['action'], $ajax_actions ) ) ) {
180
+ $load = true;
181
+ }
182
+ }
183
+ }
184
+
185
+ /**
186
+ * @deprecated 3.9.2
187
+ */
188
+ $load = apply_filters( 'wcml_load_multi_currency', $load );
189
+
190
+ /**
191
+ * @since 3.9.2
192
+ */
193
+ $load = apply_filters( 'wcml_load_multi_currency_in_ajax', $load );
194
+
195
+ return $load;
196
+ }
197
+
198
+ public function init() {
199
+
200
+ add_filter( 'wcml_get_client_currency', [ $this, 'get_client_currency' ] );
201
+ add_action( 'wp_footer', [ $this, 'maybe_show_switching_currency_prompt_dialog' ] );
202
+ add_action( 'wp_footer', [ $this, 'maybe_reset_cart_fragments' ] );
203
+
204
+ }
205
+
206
+ public function enable() {
207
+ $this->woocommerce_wpml->settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_INDEPENDENT;
208
+ $this->woocommerce_wpml->update_settings();
209
+ }
210
+
211
+ public function disable() {
212
+ $this->woocommerce_wpml->settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_DISABLED;
213
+ $this->woocommerce_wpml->update_settings();
214
+ }
215
+
216
+ public function init_currencies() {
217
+ global $sitepress;
218
+
219
+ $this->default_currency = wcml_get_woocommerce_currency_option();
220
+ $this->currencies =& $this->woocommerce_wpml->settings['currency_options'];
221
+
222
+ // Add default currency if missing (set when MC is off)
223
+ if ( ! empty( $this->default_currency ) && ! isset( $this->currencies[ $this->default_currency ] ) ) {
224
+ $this->currencies[ $this->default_currency ] = [];
225
+ }
226
+
227
+ $save_to_db = false;
228
+
229
+ $active_languages = $sitepress->get_active_languages();
230
+
231
+ $currency_defaults = [
232
+ 'rate' => 0,
233
+ 'position' => 'left',
234
+ 'thousand_sep' => ',',
235
+ 'decimal_sep' => '.',
236
+ 'num_decimals' => 2,
237
+ 'rounding' => 'disabled',
238
+ 'rounding_increment' => 1,
239
+ 'auto_subtract' => 0,
240
+ ];
241
+
242
+ foreach ( $this->currencies as $code => $currency ) {
243
+ foreach ( $currency_defaults as $key => $val ) {
244
+ if ( ! isset( $currency[ $key ] ) ) {
245
+ $this->currencies[ $code ][ $key ] = $val;
246
+ $save_to_db = true;
247
+ }
248
+ }
249
+
250
+ foreach ( $active_languages as $language ) {
251
+ if ( ! isset( $currency['languages'][ $language['code'] ] ) ) {
252
+ $this->currencies[ $code ]['languages'][ $language['code'] ] = 1;
253
+ $save_to_db = true;
254
+ }
255
+ }
256
+ }
257
+
258
+ $this->currency_codes = array_keys( $this->currencies );
259
+
260
+ // default language currencies
261
+ foreach ( $active_languages as $language ) {
262
+ if ( ! isset( $this->woocommerce_wpml->settings['default_currencies'][ $language['code'] ] ) ) {
263
+ $this->woocommerce_wpml->settings['default_currencies'][ $language['code'] ] = 0;
264
+ $save_to_db = true;
265
+ }
266
+ }
267
+
268
+ // sanity check
269
+ if ( isset( $this->woocommerce_wpml->settings['default_currencies'] ) ) {
270
+ foreach ( $this->woocommerce_wpml->settings['default_currencies'] as $language => $value ) {
271
+ if ( ! isset( $active_languages[ $language ] ) ) {
272
+ unset( $this->woocommerce_wpml->settings['default_currencies'][ $language ] );
273
+ $save_to_db = true;
274
+ }
275
+ if ( ! empty( $value ) && ! in_array( $value, $this->currency_codes ) ) {
276
+ $this->woocommerce_wpml->settings['default_currencies'][ $language ] = 0;
277
+ $save_to_db = true;
278
+ }
279
+ }
280
+ }
281
+
282
+ // add missing currencies to currencies_order
283
+ if ( isset( $this->woocommerce_wpml->settings['currencies_order'] ) ) {
284
+ foreach ( $this->currency_codes as $currency ) {
285
+ if ( ! in_array( $currency, $this->woocommerce_wpml->settings['currencies_order'] ) ) {
286
+ $this->woocommerce_wpml->settings['currencies_order'][] = $currency;
287
+ $save_to_db = true;
288
+ }
289
+ }
290
+ }
291
+
292
+ if ( $save_to_db ) {
293
+ $this->woocommerce_wpml->update_settings();
294
+ }
295
+
296
+ // force disable multi-currency when the default currency is empty
297
+ if ( empty( $this->default_currency ) ) {
298
+ $this->woocommerce_wpml->settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_DISABLED;
299
+ }
300
+
301
+ }
302
+
303
+ /**
304
+ *
305
+ * @return string
306
+ * @since 3.9.2
307
+ */
308
+ public function get_default_currency() {
309
+ return $this->default_currency;
310
+ }
311
+
312
+ public function get_currencies( $include_default = false ) {
313
+
314
+ // by default, exclude default currency
315
+ $currencies = [];
316
+ $default_currency = wcml_get_woocommerce_currency_option();
317
+
318
+ foreach ( $this->currencies as $key => $value ) {
319
+ if ( $default_currency != $key || $include_default ) {
320
+ $currencies[ $key ] = $value;
321
+ }
322
+ }
323
+
324
+ return $currencies;
325
+ }
326
+
327
+ public function get_currency_codes() {
328
+ return $this->currency_codes;
329
+ }
330
+
331
+ public function get_currency_details_by_code( $code ) {
332
+
333
+ if ( isset( $this->currencies[ $code ] ) ) {
334
+ return $this->currencies[ $code ];
335
+ }
336
+
337
+ return false;
338
+ }
339
+
340
+ public function delete_currency_by_code( $code, $settings = false, $update = true ) {
341
+ $settings = $settings ? $settings : $this->woocommerce_wpml->get_settings();
342
+ unset( $settings['currency_options'][ $code ] );
343
+
344
+ if ( isset( $settings['currencies_order'] ) ) {
345
+ foreach ( $settings['currencies_order'] as $key => $cur_code ) {
346
+ if ( $cur_code == $code ) {
347
+ unset( $settings['currencies_order'][ $key ] );
348
+ }
349
+ }
350
+ }
351
+
352
+ if ( $update ) {
353
+ $this->woocommerce_wpml->update_settings( $settings );
354
+ }
355
+
356
+ return $settings;
357
+ }
358
+
359
+ public function get_exchange_rates() {
360
+
361
+ if ( empty( $this->exchange_rates ) ) {
362
+
363
+ $this->exchange_rates = [ wcml_get_woocommerce_currency_option() => 1 ];
364
+ $woo_currencies = get_woocommerce_currencies();
365
+
366
+ $currencies = $this->get_currencies();
367
+ foreach ( $currencies as $code => $currency ) {
368
+ if ( ! empty( $woo_currencies[ $code ] ) ) {
369
+ $this->exchange_rates[ $code ] = $currency['rate'];
370
+ }
371
+ }
372
+ }
373
+
374
+ return apply_filters( 'wcml_exchange_rates', $this->exchange_rates );
375
+ }
376
+
377
+ public function get_client_currency() {
378
+ global $woocommerce, $sitepress, $wpdb;
379
+
380
+ $WCML_REST_API = new WCML_REST_API();
381
+ if (
382
+ $WCML_REST_API->is_rest_api_request() ||
383
+ ! empty( $_REQUEST['woocommerce_quick_edit'] )
384
+ ) {
385
+ return wcml_get_woocommerce_currency_option();
386
+ }
387
+
388
+ $default_currencies = $this->woocommerce_wpml->settings['default_currencies'];
389
+ $current_language = $sitepress->get_current_language();
390
+ $current_language = ( $current_language != 'all' && ! is_null( $current_language ) ) ? $current_language : $sitepress->get_default_language();
391
+
392
+ if ( ! $this->client_currency &&
393
+ isset( $this->woocommerce_wpml->settings['display_custom_prices'] ) &&
394
+ $this->woocommerce_wpml->settings['display_custom_prices'] &&
395
+ is_product()
396
+ ) {
397
+
398
+ $product_obj = wc_get_product();
399
+ $current_product_id = get_post()->ID;
400
+ $original_product_language = $this->woocommerce_wpml->products->get_original_product_language( $current_product_id );
401
+ $default = false;
402
+
403
+ if ( $product_obj->get_type() === 'variable' ) {
404
+ foreach ( $product_obj->get_children() as $child ) {
405
+ if ( ! get_post_meta( apply_filters( 'translate_object_id', $child, get_post_type( $child ), true, $original_product_language ), '_wcml_custom_prices_status', true ) ) {
406
+ $default = true;
407
+ break;
408
+ }
409
+ }
410
+ } elseif ( ! get_post_meta( apply_filters( 'translate_object_id', $current_product_id, get_post_type( $current_product_id ), true, $original_product_language ), '_wcml_custom_prices_status', true ) ) {
411
+ $default = true;
412
+ }
413
+
414
+ if ( $default ) {
415
+ $this->client_currency = wcml_get_woocommerce_currency_option();
416
+ }
417
+ }
418
+
419
+ if ( isset( $_GET['pay_for_order'] ) && $_GET['pay_for_order'] == true && isset( $_GET['key'] ) ) {
420
+ $order_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_order_key' AND meta_value = %s", sanitize_text_field( $_GET['key'] ) ) );
421
+ if ( $order_id ) {
422
+ $this->client_currency = get_post_meta( $order_id, '_order_currency', true );
423
+ }
424
+ }
425
+
426
+ if (
427
+ isset( $_POST['action'] ) &&
428
+ $_POST['action'] == 'wcml_switch_currency' &&
429
+ ! empty( $_POST['currency'] ) &&
430
+ isset( $_POST['force_switch'] ) &&
431
+ ! $_POST['force_switch'] &&
432
+ (
433
+ $this->woocommerce_wpml->settings['cart_sync']['currency_switch'] == WCML_CART_SYNC ||
434
+ $this->woocommerce_wpml->settings['cart_sync']['currency_switch'] == WCML_CART_SYNC
435
+ )
436
+ ) {
437
+ $this->client_currency = filter_input( INPUT_POST, 'currency', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
438
+ }
439
+
440
+ if ( isset( $_GET['action'] ) &&
441
+ $_GET['action'] === 'woocommerce_json_search_products_and_variations' &&
442
+ ! empty( $_COOKIE['_wcml_order_currency'] ) ) {
443
+ $this->client_currency = $_COOKIE['_wcml_order_currency'];
444
+ }
445
+
446
+ if ( is_null( $this->client_currency ) &&
447
+ isset( $default_currencies[ $current_language ] ) &&
448
+ $default_currencies[ $current_language ] &&
449
+ ! empty( $woocommerce->session ) &&
450
+ $current_language != $woocommerce->session->get( 'client_currency_language' ) ) {
451
+
452
+ $current_currency = $woocommerce->session->get( 'client_currency' );
453
+ $client_currency = $default_currencies[ $current_language ];
454
+ $prevent_switching = apply_filters( 'wcml_switch_currency_exception', false, $current_currency, $client_currency, true );
455
+
456
+ $this->client_currency = $client_currency;
457
+ if ( ! array_key_exists( 'force_switch', $_POST ) && $prevent_switching ) {
458
+ $this->switching_currency_html = $prevent_switching['prevent_switching'];
459
+ }
460
+ }
461
+
462
+ // edit order page
463
+ if ( isset( $_SERVER['HTTP_REFERER'] ) ) {
464
+ $arg = parse_url( $_SERVER['HTTP_REFERER'] );
465
+ if ( isset( $arg['query'] ) ) {
466
+ parse_str( $arg['query'], $arg );
467
+ if ( isset( $arg['post'] ) && get_post_type( $arg['post'] ) == 'shop_order' ) {
468
+ $this->client_currency = get_post_meta( $arg['post'], '_order_currency', true );
469
+ }
470
+ }
471
+ }
472
+
473
+ // client currency in general / if enabled for this language
474
+ if ( is_null( $this->client_currency ) && ! empty( $woocommerce->session ) ) {
475
+ $session_currency = $woocommerce->session->get( 'client_currency' );
476
+ if ( $session_currency && ! empty( $this->currencies[ $session_currency ]['languages'][ $current_language ] ) ) {
477
+
478
+ $this->client_currency = $woocommerce->session->get( 'client_currency' );
479
+ }
480
+ }
481
+
482
+ if ( is_null( $this->client_currency ) ) {
483
+ $woocommerce_currency = wcml_get_woocommerce_currency_option();
484
+
485
+ // fall on WC currency if enabled for this language
486
+ if ( ! empty( $this->currencies[ $woocommerce_currency ]['languages'][ $current_language ] ) ) {
487
+ $this->client_currency = $woocommerce_currency;
488
+ } else {
489
+ // first currency enabled for this language
490
+ foreach ( $this->currencies as $code => $data ) {
491
+ if ( ! empty( $data['languages'][ $current_language ] ) ) {
492
+ $this->client_currency = $code;
493
+ break;
494
+ }
495
+ }
496
+ }
497
+ }
498
+
499
+ $this->client_currency = apply_filters( 'wcml_client_currency', $this->client_currency );
500
+
501
+ if ( ! empty( $woocommerce->session ) && $this->client_currency ) {
502
+ $woocommerce->session->set( 'client_currency', $this->client_currency );
503
+ $woocommerce->session->set( 'client_currency_language', $current_language );
504
+ }
505
+
506
+ return $this->client_currency;
507
+ }
508
+
509
+ public function maybe_show_switching_currency_prompt_dialog() {
510
+ if ( $this->switching_currency_html ) {
511
+ echo $this->switching_currency_html;
512
+ }
513
+ }
 
 
 
514
 
515
  public function maybe_reset_cart_fragments() {
516
  global $woocommerce;
518
  if ( ! empty( $woocommerce->session ) && $woocommerce->session->get( 'client_currency_switched' ) ) {
519
  ?>
520
  <script type="text/javascript">
521
+ jQuery(document).ready(function () {
522
+ wcml_reset_cart_fragments();
523
+ });
524
  </script>
525
  <?php
526
  $woocommerce->session->set( 'client_currency_switched', false );
528
 
529
  }
530
 
531
+ public function set_client_currency( $currency ) {
532
+ global $woocommerce, $sitepress;
533
 
534
+ $this->client_currency = $currency;
535
 
536
+ $woocommerce->session->set( 'client_currency', $currency );
537
+ $woocommerce->session->set( 'client_currency_language', $sitepress->get_current_language() );
538
 
539
+ do_action( 'wcml_set_client_currency', $currency );
540
 
541
+ }
542
 
543
+ public function switch_currency() {
544
 
545
+ $currency = filter_input( INPUT_POST, 'currency', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
546
+ $force_switch = filter_input( INPUT_POST, 'force_switch', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
547
 
548
+ do_action( 'wcml_before_switch_currency', $currency, $force_switch );
 
549
 
550
+ if ( ! $force_switch && apply_filters( 'wcml_switch_currency_exception', false, $this->client_currency, $currency ) ) {
551
+ die();
552
+ }
553
 
554
+ $this->set_client_currency( $currency, $force_switch );
 
 
555
 
556
+ // force set user cookie when user is not logged in
557
+ global $woocommerce, $current_user;
558
+ if ( empty( $woocommerce->session->data ) && empty( $current_user->ID ) ) {
559
+ $woocommerce->session->set_customer_session_cookie( true );
560
+ }
561
 
562
+ $woocommerce->session->set( 'client_currency_switched', true );
 
 
 
 
563
 
564
+ do_action( 'wcml_switch_currency', $currency );
565
 
566
+ echo json_encode( [] );
567
+ die();
568
 
569
+ }
 
570
 
571
+ public function get_currencies_without_cents() {
572
 
573
+ return apply_filters( 'wcml_currencies_without_cents', $this->currencies_without_cents );
574
+ }
575
 
576
+ }
 
577
 
 
inc/wcml-switch-lang-request.php CHANGED
@@ -50,7 +50,7 @@ class WCML_Switch_Lang_Request{
50
  }
51
 
52
  /**
53
- * @return string language code stored in the user's wp_wpml_current_language cookie
54
  */
55
  public function get_cookie_lang() {
56
  global $wpml_language_resolution;
@@ -65,7 +65,7 @@ class WCML_Switch_Lang_Request{
65
 
66
  public function get_cookie_name() {
67
 
68
- return 'wp_wpml_current_language';
69
  }
70
 
71
  /**
50
  }
51
 
52
  /**
53
+ * @return string language code stored in the user's wp-wpml_current_language cookie
54
  */
55
  public function get_cookie_lang() {
56
  global $wpml_language_resolution;
65
 
66
  public function get_cookie_name() {
67
 
68
+ return 'wp-wpml_current_language';
69
  }
70
 
71
  /**
readme.txt CHANGED
@@ -5,7 +5,7 @@ Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multili
5
  License: GPLv2
6
  Requires at least: 4.7
7
  Tested up to: 5.2.4
8
- Stable tag: 4.7.0
9
 
10
  Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
5
  License: GPLv2
6
  Requires at least: 4.7
7
  Tested up to: 5.2.4
8
+ Stable tag: 4.7.2
9
 
10
  Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
vendor/autoload.php CHANGED
@@ -4,4 +4,4 @@
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
- return ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726::getLoader();
4
 
5
  require_once __DIR__ . '/composer/autoload_real.php';
6
 
7
+ return ComposerAutoloaderInit4805846488f79a5e99bdcddaade3fb08::getLoader();
vendor/composer/autoload_real.php CHANGED
@@ -2,7 +2,7 @@
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
- class ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726
6
  {
7
  private static $loader;
8
 
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726
19
  return self::$loader;
20
  }
21
 
22
- spl_autoload_register(array('ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
- spl_autoload_unregister(array('ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
- call_user_func(\Composer\Autoload\ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
@@ -48,19 +48,19 @@ class ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
- $includeFiles = Composer\Autoload\ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
- composerRequire7548bcfb7ce4453e35146fd7c53e1726($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
- function composerRequire7548bcfb7ce4453e35146fd7c53e1726($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
2
 
3
  // autoload_real.php @generated by Composer
4
 
5
+ class ComposerAutoloaderInit4805846488f79a5e99bdcddaade3fb08
6
  {
7
  private static $loader;
8
 
19
  return self::$loader;
20
  }
21
 
22
+ spl_autoload_register(array('ComposerAutoloaderInit4805846488f79a5e99bdcddaade3fb08', 'loadClassLoader'), true, true);
23
  self::$loader = $loader = new \Composer\Autoload\ClassLoader();
24
+ spl_autoload_unregister(array('ComposerAutoloaderInit4805846488f79a5e99bdcddaade3fb08', 'loadClassLoader'));
25
 
26
  $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
27
  if ($useStaticLoader) {
28
  require_once __DIR__ . '/autoload_static.php';
29
 
30
+ call_user_func(\Composer\Autoload\ComposerStaticInit4805846488f79a5e99bdcddaade3fb08::getInitializer($loader));
31
  } else {
32
  $map = require __DIR__ . '/autoload_namespaces.php';
33
  foreach ($map as $namespace => $path) {
48
  $loader->register(true);
49
 
50
  if ($useStaticLoader) {
51
+ $includeFiles = Composer\Autoload\ComposerStaticInit4805846488f79a5e99bdcddaade3fb08::$files;
52
  } else {
53
  $includeFiles = require __DIR__ . '/autoload_files.php';
54
  }
55
  foreach ($includeFiles as $fileIdentifier => $file) {
56
+ composerRequire4805846488f79a5e99bdcddaade3fb08($fileIdentifier, $file);
57
  }
58
 
59
  return $loader;
60
  }
61
  }
62
 
63
+ function composerRequire4805846488f79a5e99bdcddaade3fb08($fileIdentifier, $file)
64
  {
65
  if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
66
  require $file;
vendor/composer/autoload_static.php CHANGED
@@ -4,7 +4,7 @@
4
 
5
  namespace Composer\Autoload;
6
 
7
- class ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726
8
  {
9
  public static $files = array (
10
  'b45b351e6b6f7487d819961fef2fda77' => __DIR__ . '/..' . '/jakeasmith/http_build_url/src/http_build_url.php',
@@ -235,9 +235,9 @@ class ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726
235
  public static function getInitializer(ClassLoader $loader)
236
  {
237
  return \Closure::bind(function () use ($loader) {
238
- $loader->prefixLengthsPsr4 = ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726::$prefixLengthsPsr4;
239
- $loader->prefixDirsPsr4 = ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726::$prefixDirsPsr4;
240
- $loader->classMap = ComposerStaticInit7548bcfb7ce4453e35146fd7c53e1726::$classMap;
241
 
242
  }, null, ClassLoader::class);
243
  }
4
 
5
  namespace Composer\Autoload;
6
 
7
+ class ComposerStaticInit4805846488f79a5e99bdcddaade3fb08
8
  {
9
  public static $files = array (
10
  'b45b351e6b6f7487d819961fef2fda77' => __DIR__ . '/..' . '/jakeasmith/http_build_url/src/http_build_url.php',
235
  public static function getInitializer(ClassLoader $loader)
236
  {
237
  return \Closure::bind(function () use ($loader) {
238
+ $loader->prefixLengthsPsr4 = ComposerStaticInit4805846488f79a5e99bdcddaade3fb08::$prefixLengthsPsr4;
239
+ $loader->prefixDirsPsr4 = ComposerStaticInit4805846488f79a5e99bdcddaade3fb08::$prefixDirsPsr4;
240
+ $loader->classMap = ComposerStaticInit4805846488f79a5e99bdcddaade3fb08::$classMap;
241
 
242
  }, null, ClassLoader::class);
243
  }
wpml-woocommerce.php CHANGED
@@ -8,7 +8,7 @@
8
  * Text Domain: woocommerce-multilingual
9
  * Requires at least: 4.7
10
  * Tested up to: 5.2.4
11
- * Version: 4.7.1
12
  * Plugin Slug: woocommerce-multilingual
13
  * WC requires at least: 3.3.0
14
  * WC tested up to: 3.7.1
@@ -33,7 +33,7 @@ if ( ! $wpml_php_version_check->is_ok() ) {
33
  return;
34
  }
35
 
36
- define( 'WCML_VERSION', '4.7.1' );
37
  define( 'WCML_PLUGIN_PATH', dirname( __FILE__ ) );
38
  define( 'WCML_PLUGIN_FOLDER', basename( WCML_PLUGIN_PATH ) );
39
  define( 'WCML_LOCALE_PATH', WCML_PLUGIN_PATH . '/locale' );
8
  * Text Domain: woocommerce-multilingual
9
  * Requires at least: 4.7
10
  * Tested up to: 5.2.4
11
+ * Version: 4.7.2
12
  * Plugin Slug: woocommerce-multilingual
13
  * WC requires at least: 3.3.0
14
  * WC tested up to: 3.7.1
33
  return;
34
  }
35
 
36
+ define( 'WCML_VERSION', '4.7.2' );
37
  define( 'WCML_PLUGIN_PATH', dirname( __FILE__ ) );
38
  define( 'WCML_PLUGIN_FOLDER', basename( WCML_PLUGIN_PATH ) );
39
  define( 'WCML_LOCALE_PATH', WCML_PLUGIN_PATH . '/locale' );