Version Description
Download this release
Release Info
Developer | sergey.r |
Plugin | 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 +0 -3
- changelog/4.7.2.md +6 -0
- classes/product/class-wcml-product-data-store-cpt.php +3 -1
- classes/shortcodes/class-wcml-wc-shortcode-product-category.php +18 -7
- inc/class-wcml-ajax-setup.php +38 -33
- inc/class-wcml-endpoints.php +1 -1
- inc/class-wcml-wc-shipping.php +4 -1
- inc/currencies/class-wcml-multi-currency.php +535 -539
- inc/wcml-switch-lang-request.php +2 -2
- readme.txt +1 -1
- vendor/autoload.php +1 -1
- vendor/composer/autoload_real.php +7 -7
- vendor/composer/autoload_static.php +4 -4
- wpml-woocommerce.php +2 -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 |
-
|
|
|
|
|
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 |
-
$
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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
|
54 |
-
* @param
|
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'] =
|
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 |
-
|
17 |
|
18 |
-
|
19 |
-
|
20 |
|
21 |
-
|
22 |
-
|
23 |
|
24 |
-
|
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 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
61 |
if ( $action && ( $is_ajax_action || ! apply_filters( 'wcml_is_localize_woocommerce_on_ajax', true, $action ) ) ) {
|
62 |
return;
|
63 |
}
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
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',
|
83 |
-
|
84 |
|
85 |
}
|
86 |
|
@@ -89,11 +94,11 @@ class WCML_Ajax_Setup{
|
|
89 |
|
90 |
|
91 |
/**
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
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 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
public $currency_switcher_ajax;
|
61 |
/**
|
62 |
* @var WCML_Multi_Currency_Install
|
63 |
*/
|
64 |
public $install;
|
65 |
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
154 |
-
|
155 |
-
|
156 |
-
|
157 |
-
|
158 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
170 |
-
|
171 |
-
|
172 |
-
|
173 |
-
|
174 |
-
|
175 |
-
|
176 |
-
|
177 |
-
|
178 |
-
|
179 |
-
|
180 |
-
|
181 |
-
|
182 |
-
|
183 |
-
|
184 |
-
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
-
|
192 |
-
|
193 |
-
|
194 |
-
|
195 |
-
|
196 |
-
|
197 |
-
|
198 |
-
|
199 |
-
|
200 |
-
|
201 |
-
|
202 |
-
|
203 |
-
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
|
208 |
-
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
-
|
216 |
-
|
217 |
-
|
218 |
-
|
219 |
-
|
220 |
-
|
221 |
-
|
222 |
-
|
223 |
-
|
224 |
-
|
225 |
-
|
226 |
-
|
227 |
-
|
228 |
-
|
229 |
-
|
230 |
-
|
231 |
-
|
232 |
-
|
233 |
-
|
234 |
-
|
235 |
-
|
236 |
-
|
237 |
-
|
238 |
-
|
239 |
-
|
240 |
-
|
241 |
-
|
242 |
-
|
243 |
-
|
244 |
-
|
245 |
-
|
246 |
-
|
247 |
-
|
248 |
-
|
249 |
-
|
250 |
-
|
251 |
-
|
252 |
-
|
253 |
-
|
254 |
-
|
255 |
-
|
256 |
-
|
257 |
-
|
258 |
-
|
259 |
-
|
260 |
-
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
290 |
-
|
291 |
-
|
292 |
-
|
293 |
-
|
294 |
-
|
295 |
-
|
296 |
-
|
297 |
-
|
298 |
-
|
299 |
-
|
300 |
-
|
301 |
-
|
302 |
-
|
303 |
-
|
304 |
-
|
305 |
-
|
306 |
-
|
307 |
-
|
308 |
-
|
309 |
-
|
310 |
-
|
311 |
-
|
312 |
-
|
313 |
-
|
314 |
-
|
315 |
-
|
316 |
-
|
317 |
-
|
318 |
-
|
319 |
-
|
320 |
-
|
321 |
-
|
322 |
-
|
323 |
-
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
331 |
-
|
332 |
-
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
|
350 |
-
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
-
|
359 |
-
|
360 |
-
|
361 |
-
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
-
|
366 |
-
|
367 |
-
|
368 |
-
|
369 |
-
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
377 |
-
|
378 |
-
|
379 |
-
|
380 |
-
|
381 |
-
|
382 |
-
|
383 |
-
|
384 |
-
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
|
400 |
-
|
401 |
-
|
402 |
-
|
403 |
-
|
404 |
-
|
405 |
-
|
406 |
-
|
407 |
-
|
408 |
-
|
409 |
-
|
410 |
-
|
411 |
-
|
412 |
-
|
413 |
-
|
414 |
-
|
415 |
-
|
416 |
-
|
417 |
-
|
418 |
-
|
419 |
-
|
420 |
-
|
421 |
-
|
422 |
-
|
423 |
-
|
424 |
-
|
425 |
-
|
426 |
-
|
427 |
-
|
428 |
-
|
429 |
-
|
430 |
-
|
431 |
-
|
432 |
-
|
433 |
-
|
434 |
-
|
435 |
-
|
436 |
-
|
437 |
-
|
438 |
-
|
439 |
-
|
440 |
-
|
441 |
-
|
442 |
-
|
443 |
-
|
444 |
-
|
445 |
-
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
|
450 |
-
|
451 |
-
|
452 |
-
|
453 |
-
|
454 |
-
|
455 |
-
|
456 |
-
|
457 |
-
|
458 |
-
|
459 |
-
|
460 |
-
|
461 |
-
|
462 |
-
|
463 |
-
|
464 |
-
|
465 |
-
|
466 |
-
|
467 |
-
|
468 |
-
|
469 |
-
|
470 |
-
|
471 |
-
|
472 |
-
|
473 |
-
|
474 |
-
|
475 |
-
|
476 |
-
|
477 |
-
|
478 |
-
|
479 |
-
|
480 |
-
|
481 |
-
|
482 |
-
|
483 |
-
|
484 |
-
|
485 |
-
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
|
490 |
-
|
491 |
-
|
492 |
-
|
493 |
-
|
494 |
-
|
495 |
-
|
496 |
-
|
497 |
-
|
498 |
-
|
499 |
-
|
500 |
-
|
501 |
-
|
502 |
-
|
503 |
-
|
504 |
-
|
505 |
-
|
506 |
-
|
507 |
-
|
508 |
-
|
509 |
-
|
510 |
-
|
511 |
-
|
512 |
-
|
513 |
-
|
514 |
-
|
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 |
-
|
526 |
-
|
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 |
-
|
536 |
-
|
537 |
|
538 |
-
|
539 |
|
540 |
-
|
541 |
-
|
542 |
|
|
|
543 |
|
544 |
-
|
545 |
|
546 |
-
|
547 |
|
548 |
-
|
|
|
549 |
|
550 |
-
|
551 |
-
$force_switch = filter_input( INPUT_POST, 'force_switch', FILTER_SANITIZE_FULL_SPECIAL_CHARS );
|
552 |
|
553 |
-
|
|
|
|
|
554 |
|
555 |
-
|
556 |
-
die();
|
557 |
-
}
|
558 |
|
559 |
-
|
|
|
|
|
|
|
|
|
560 |
|
561 |
-
|
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 |
-
|
568 |
|
569 |
-
|
|
|
570 |
|
571 |
-
|
572 |
-
die();
|
573 |
|
574 |
-
|
575 |
|
576 |
-
|
|
|
577 |
|
578 |
-
|
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 |
-
|
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 |
-
|
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.
|
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
|
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
|
6 |
{
|
7 |
private static $loader;
|
8 |
|
@@ -19,15 +19,15 @@ class ComposerAutoloaderInit7548bcfb7ce4453e35146fd7c53e1726
|
|
19 |
return self::$loader;
|
20 |
}
|
21 |
|
22 |
-
spl_autoload_register(array('
|
23 |
self::$loader = $loader = new \Composer\Autoload\ClassLoader();
|
24 |
-
spl_autoload_unregister(array('
|
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\
|
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\
|
52 |
} else {
|
53 |
$includeFiles = require __DIR__ . '/autoload_files.php';
|
54 |
}
|
55 |
foreach ($includeFiles as $fileIdentifier => $file) {
|
56 |
-
|
57 |
}
|
58 |
|
59 |
return $loader;
|
60 |
}
|
61 |
}
|
62 |
|
63 |
-
function
|
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
|
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 =
|
239 |
-
$loader->prefixDirsPsr4 =
|
240 |
-
$loader->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.
|
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.
|
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' );
|