PluginProbe ʕ •ᴥ•ʔ
WPML Multilingual & Multicurrency for WooCommerce / 5.5.7
WPML Multilingual & Multicurrency for WooCommerce v5.5.7
5.5.7 5.3.8 5.3.9 5.4.3 5.4.4 5.4.5 5.5.1 5.5.1.1 5.5.2.2 5.5.2.3 5.5.3 5.5.3.1 5.5.4 5.5.5 5.5.6 trunk 0.9 1.0 1.1 1.2 1.3 1.4 1.5 2.0 2.2 2.3 2.3.1 2.3.2 3.0 3.0.1 3.1 3.2 3.2.1 3.2.2 3.3 3.3.1 3.3.2 3.3.3 3.3.4 3.4 3.4.1 3.4.2 3.4.3 3.5 3.5.1 3.5.2 3.5.3 3.5.4 3.5.5 3.6 3.6.1 3.6.10 3.6.11 3.6.2 3.6.3 3.6.4 3.6.5 3.6.5.1 3.6.6 3.6.7 3.6.8 3.6.9 3.7 3.7.1 3.7.10 3.7.11 3.7.12 3.7.13 3.7.14 3.7.15 3.7.16 3.7.2 3.7.3 3.7.4 3.7.5 3.7.6 3.7.7 3.7.8 3.7.9 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.8.6 3.9.0 3.9.1 3.9.1.1 3.9.2 3.9.3 3.9.4 3.9.5 4.0.0 4.0.1 4.0.2 4.0.3 4.0.4 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.10.0 4.10.1 4.10.2 4.10.3 4.10.4 4.11.2 4.11.3.2 4.11.5 4.11.6 4.12.1 4.12.4 4.12.5 4.12.6 4.2.0 4.2.0.1 4.2.1 4.2.1.1 4.2.10 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.7.1 4.2.8 4.2.8.1 4.2.9 4.3.0 4.3.1 4.3.2 4.3.2.1 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.4.0 4.4.1 4.4.2 4.4.2.1 4.5.0 4.6.0 4.6.1 4.6.2 4.6.2.1 4.6.3 4.6.5 4.6.6 4.6.7 4.7.0 4.7.1 4.7.2 4.7.3 4.7.4 4.7.5 4.7.6 4.7.7 4.7.8 4.7.9 4.8.0 4.9.0 4.9.1 5.0.1 5.0.2 5.1.1 5.1.2 5.1.3 5.2.0 5.2.1 5.3.2 5.3.3.1 5.3.4 5.3.5 5.3.6 5.3.7
woocommerce-multilingual / inc / class-wcml-upgrade.php
woocommerce-multilingual / inc Last commit date
admin-menus 2 weeks ago currencies 2 weeks ago template-classes 2 weeks ago translation-editor 2 weeks ago class-wcml-ajax-setup.php 2 weeks ago class-wcml-attributes.php 2 weeks ago class-wcml-capabilities.php 2 weeks ago class-wcml-cart-removed-items-widget.php 1 year ago class-wcml-cart-switch-lang-functions.php 2 weeks ago class-wcml-cart-sync-warnings.php 2 weeks ago class-wcml-cart.php 2 weeks ago class-wcml-comments.php 2 weeks ago class-wcml-compatibility.php 2 weeks ago class-wcml-coupons.php 2 weeks ago class-wcml-dependencies.php 2 weeks ago class-wcml-emails.php 2 weeks ago class-wcml-endpoints.php 2 weeks ago class-wcml-install.php 2 weeks ago class-wcml-languages-upgrader.php 2 weeks ago class-wcml-locale.php 2 weeks ago class-wcml-orders.php 2 weeks ago class-wcml-products-screen-options.php 2 weeks ago class-wcml-products.php 2 weeks ago class-wcml-reports.php 2 weeks ago class-wcml-requests.php 2 weeks ago class-wcml-resources.php 2 weeks ago class-wcml-store-pages.php 2 weeks ago class-wcml-terms.php 2 weeks ago class-wcml-tp-support.php 2 weeks ago class-wcml-troubleshooting.php 2 weeks ago class-wcml-upgrade.php 2 weeks ago class-wcml-url-translation.php 2 weeks ago class-wcml-wc-gateways.php 2 weeks ago class-wcml-wc-shipping.php 2 weeks ago class-wcml-wc-strings.php 2 weeks ago class-wcml-widgets.php 2 weeks ago constants.php 2 weeks ago functions-pure.php 2 weeks ago functions.php 2 weeks ago installer-loader.php 2 weeks ago missing-php-functions.php 2 weeks ago wcml-core-functions.php 2 weeks ago wcml-switch-lang-request.php 2 weeks ago
class-wcml-upgrade.php
913 lines
1 <?php
2
3 use WCML\MultiCurrency\Settings as McSettings;
4 use Automattic\WooCommerce\Internal\ProductAttributesLookup\DataRegenerator;
5 use Automattic\WooCommerce\Internal\ProductAttributesLookup\LookupDataStore;
6 use WCML\Attributes\LookupTableFactory;
7 use WCML\Utilities\DB;
8 use WCML\Utilities\WCTaxonomies;
9 use function WCML\functions\getSitePress;
10 use function WCML\functions\isStandAlone;
11
12 class WCML_Upgrade {
13
14 private $versions = [
15 '2.9.9.1',
16 '3.1',
17 '3.2',
18 '3.3',
19 '3.5',
20 '3.5.4',
21 '3.6',
22 '3.7',
23 '3.7.3',
24 '3.7.11',
25 '3.8',
26 '3.9',
27 '3.9.1',
28 '4.0',
29 '4.1.0',
30 '4.2.0',
31 '4.2.2',
32 '4.2.7',
33 '4.2.10',
34 '4.2.11',
35 '4.3.0',
36 '4.3.4',
37 '4.3.5',
38 '4.4.1',
39 '4.4.3',
40 '4.6.8',
41 '4.7.3',
42 '4.7.6',
43 '4.7.8',
44 '4.10.0',
45 '4.11.0',
46 '4.12.0',
47 '5.0.0',
48 '5.3.0',
49 '5.4.1',
50 '5.4.4',
51 '5.5.2',
52 ];
53
54 public function __construct() {
55 add_action( 'init', [ $this, 'run' ] );
56 add_action( 'init', [ $this, 'setup_upgrade_notices' ] );
57 add_action( 'admin_notices', [ $this, 'show_upgrade_notices' ] );
58
59 add_action( 'wp_ajax_wcml_hide_notice', [ $this, 'hide_upgrade_notice' ] );
60 }
61
62 public function setup_upgrade_notices() {
63 $wcml_settings = get_option( '_wcml_settings' );
64 $version_in_db = get_option( '_wcml_version' );
65
66 if ( ! empty( $version_in_db ) && version_compare( $version_in_db, '2.9.9.1', '<' ) ) {
67 $n = 'varimages';
68 $wcml_settings['notifications'][ $n ] =
69 [
70 'show' => 1,
71 'text' => __( 'Looks like you are upgrading from a previous version of WPML Multilingual & Multicurrency for WooCommerce. Would you like to automatically create translated variations and images?', 'woocommerce-multilingual' ) .
72 '<br /><strong>' .
73 ' <a href="' . \WCML\Utilities\AdminUrl::getTroubleshootingTab() . '">' . __( 'Yes, go to the troubleshooting page', 'woocommerce-multilingual' ) . '</a> |' .
74 ' <a href="#" onclick="jQuery.ajax({type:\'POST\',url: ajaxurl,data:\'action=wcml_hide_notice&notice=' . $n . '\',success:function(){jQuery(\'#' . $n . '\').fadeOut()}});return false;">' . __( 'No - dismiss', 'woocommerce-multilingual' ) . '</a>' .
75 '</strong>',
76 ];
77 update_option( '_wcml_settings', $wcml_settings );
78 }
79 }
80
81 public function show_upgrade_notices() {
82 $wcml_settings = get_option( '_wcml_settings' );
83 if ( ! empty( $wcml_settings['notifications'] ) ) {
84 foreach ( $wcml_settings['notifications'] as $k => $notification ) {
85
86 if ( isset( $_GET['tab'] ) && \WCML\Utilities\AdminUrl::TAB_TROUBLESHOOTING === $_GET['tab'] && 'varimages' === $k ) {
87 continue;
88 }
89
90 if ( $notification['show'] ) {
91 ?>
92 <div id="<?php echo esc_attr( $k ); ?>" class="updated">
93 <p><?php echo $notification['text']; ?></p>
94 </div>
95 <?php
96 }
97 }
98 }
99 }
100
101 public function hide_upgrade_notice( $k ) {
102 if ( empty( $k ) ) {
103 $k = $_POST['notice'];
104 }
105
106 $wcml_settings = get_option( '_wcml_settings' );
107 if ( isset( $wcml_settings['notifications'][ $k ] ) ) {
108 $wcml_settings['notifications'][ $k ]['show'] = 0;
109 update_option( '_wcml_settings', $wcml_settings );
110 }
111 }
112
113 public function run() {
114 $version_in_db = get_option( '_wcml_version' );
115
116 if ( empty( $version_in_db ) && get_option( 'icl_is_wcml_installed' ) ) {
117 $version_in_db = '2.3.2';
118 }
119
120 $migration_ran = false;
121
122 if ( $version_in_db && version_compare( $version_in_db, WCML_VERSION, '<' ) ) {
123 foreach ( $this->versions as $version ) {
124 if ( version_compare( $version, $version_in_db, '>' ) ) {
125 $upgrade_method = 'upgrade_' . str_replace( '.', '_', $version );
126
127 if ( method_exists( $this, $upgrade_method ) ) {
128 $this->$upgrade_method();
129 $migration_ran = true;
130 }
131 }
132 }
133 }
134
135 if ( $migration_ran || empty( $version_in_db ) ) {
136 update_option( '_wcml_version', WCML_VERSION );
137 }
138
139 if ( get_option( '_wcml_4_1_0_migration_required' ) && class_exists( 'woocommerce' ) ) {
140 $this->upgrade_4_1_0();
141 delete_option( '_wcml_4_1_0_migration_required' );
142 }
143 }
144
145 public function upgrade_2_9_9_1() {
146 global $wpdb;
147
148 $currencies = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'icl_currencies ORDER BY id DESC' );
149
150 foreach ( $currencies as $currency ) {
151 if ( isset( $currency->language_code ) ) {
152 $wpdb->insert(
153 $wpdb->prefix . 'icl_languages_currencies',
154 [
155 'language_code' => $currency->language_code,
156 'currency_id' => $currency->id,
157 ]
158 );
159 }
160 }
161
162 $cols = $wpdb->get_col( "SHOW COLUMNS FROM {$wpdb->prefix}icl_currencies" );
163 if ( in_array( 'language_code', $cols ) ) {
164 $wpdb->query( "ALTER TABLE {$wpdb->prefix}icl_currencies DROP COLUMN language_code" );
165 }
166
167 $new_settings = [
168 'is_term_order_synced' => get_option( 'icl_is_wcml_term_order_synched' ),
169 'file_path_sync' => get_option( 'wcml_file_path_sync' ),
170 'is_installed' => get_option( 'icl_is_wpcml_installed' ),
171 'dismiss_doc_main' => get_option( 'wpml_dismiss_doc_main' ),
172 'enable_multi_currency' => get_option( 'icl_enable_multi_currency' ),
173 'currency_converting_option' => get_option( 'currency_converting_option' ),
174 ];
175
176 if ( ! get_option( '_wcml_settings' ) ) {
177 add_option( '_wcml_settings', $new_settings, '', true );
178 }
179
180 delete_option( 'icl_is_wcml_term_order_synced' );
181 delete_option( 'wcml_file_path_sync' );
182 delete_option( 'icl_is_wpcml_installed' );
183 delete_option( 'wpml_dismiss_doc_main' );
184 delete_option( 'icl_enable_multi_currency' );
185 delete_option( 'currency_converting_option' );
186
187 }
188
189 public function upgrade_3_1() {
190 global $wpdb, $sitepress;
191 $wcml_settings = get_option( '_wcml_settings' );
192
193 if ( isset( $wcml_settings['enable_multi_currency'] ) && 'yes' === $wcml_settings['enable_multi_currency'] ) {
194 $wcml_settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_INDEPENDENT;
195 } else {
196 $wcml_settings['enable_multi_currency'] = WCML_MULTI_CURRENCIES_DISABLED;
197 }
198
199 $wcml_settings['products_sync_date'] = 1;
200
201 update_option( '_wcml_settings', $wcml_settings );
202
203 if ( 'yes' === $wcml_settings['enable_multi_currency'] && 2 === (int) $wcml_settings['currency_converting_option'] ) {
204
205 $results = $wpdb->get_results( "SELECT l.language_code, c.code FROM {$wpdb->prefix}icl_languages_currencies l JOIN {$wpdb->prefix}icl_currencies c ON l.currency_id = c.id" );
206 foreach ( $results as $row ) {
207 $language_currencies[ $row->language_code ] = $row->code;
208 }
209
210 $results = $wpdb->get_results(
211 $wpdb->prepare(
212 "
213 SELECT p.ID, t.trid, t.element_type
214 FROM {$wpdb->posts} p JOIN {$wpdb->prefix}icl_translations t ON t.element_id = p.ID AND t.element_type IN ('post_product', 'post_product_variation')
215 WHERE
216 p.post_type in ('product', 'product_variation') AND t.language_code = %s
217
218 ",
219 $sitepress->get_default_language()
220 )
221 );
222
223 foreach ( $results as $row ) {
224 $translations = $sitepress->get_element_translations( $row->trid, $row->element_type );
225 $meta = get_post_meta( $row->ID );
226 $original_prices['_price'] = ! empty( $meta['_price'] ) ? $meta['_price'][0] : 0;
227 $original_prices['_regular_price'] = ! empty( $meta['_regular_price'] ) ? $meta['_regular_price'][0] : 0;
228 $original_prices['_sale_price'] = ! empty( $meta['_sale_price'] ) ? $meta['_sale_price'][0] : 0;
229
230 $ccr = [];
231
232 foreach ( $translations as $translation ) {
233 if ( isset( $language_currencies ) && $translation->element_id != $row->ID ) {
234 $meta = get_post_meta( $translation->element_id );
235 $translated_prices['_price'] = $meta['_price'][0];
236 $translated_prices['_regular_price'] = $meta['_regular_price'][0];
237 $translated_prices['_sale_price'] = $meta['_sale_price'][0];
238
239 if ( ! empty( $translated_prices['_price'] ) && ! empty( $original_prices['_price'] ) && $translated_prices['_price'] != $original_prices['_price'] ) {
240 $ccr['_price'][ $language_currencies[ $translation->language_code ] ] = $translated_prices['_price'] / $original_prices['_price'];
241 }
242
243 if ( ! empty( $translated_prices['_regular_price'] ) && ! empty( $original_prices['_regular_price'] ) && $translated_prices['_regular_price'] != $original_prices['_regular_price'] ) {
244 $ccr['_regular_price'][ $language_currencies[ $translation->language_code ] ] = $translated_prices['_regular_price'] / $original_prices['_regular_price'];
245 }
246
247 if ( ! empty( $translated_prices['_sale_price'] ) && ! empty( $original_prices['_sale_price'] ) && $translated_prices['_sale_price'] != $original_prices['_sale_price'] ) {
248 $ccr['_sale_price'][ $language_currencies[ $translation->language_code ] ] = $translated_prices['_sale_price'] / $original_prices['_sale_price'];
249 }
250 }
251 }
252
253 if ( $ccr ) {
254 update_post_meta( $row->ID, '_custom_conversion_rate', $ccr );
255 }
256 }
257 }
258
259 }
260
261 public function upgrade_3_2() {
262 WCML_Capabilities::set_up_capabilities();
263
264 global $wpdb;
265 $currencies = $wpdb->get_results( 'SELECT id,code FROM ' . $wpdb->prefix . 'icl_currencies ORDER BY `id` DESC' );
266 $wc_currencies = get_woocommerce_currencies();
267 foreach ( $currencies as $currency ) {
268 if ( ! array_key_exists( $currency->code, $wc_currencies ) ) {
269 $wpdb->delete( $wpdb->prefix . 'icl_currencies', [ 'ID' => $currency->id ] );
270 }
271 }
272 }
273
274 public function upgrade_3_3() {
275 global $wpdb, $woocommerce_wpml;
276
277 WCML_Capabilities::set_up_capabilities();
278
279 $currencies = $wpdb->get_results( 'SELECT * FROM ' . $wpdb->prefix . 'icl_currencies ORDER BY `id` ASC', OBJECT );
280 if ( $currencies ) {
281 foreach ( $currencies as $currency ) {
282 $woocommerce_wpml->settings['currency_options'][ $currency->code ]['rate'] = $currency->value;
283 $woocommerce_wpml->settings['currency_options'][ $currency->code ]['updated'] = $currency->changed;
284 $woocommerce_wpml->settings['currency_options'][ $currency->code ]['position'] = 'left';
285 $woocommerce_wpml->settings['currency_options'][ $currency->code ]['languages'] = $woocommerce_wpml->settings['currencies_languages'];
286 unset( $woocommerce_wpml->settings['currencies_languages'] );
287
288 $woocommerce_wpml->update_settings();
289 }
290 }
291
292 $wpdb->query( "DROP TABLE `{$wpdb->prefix}icl_currencies`" );
293 }
294
295 public function upgrade_3_5() {
296 $wcml_settings = get_option( '_wcml_settings' );
297
298 $wcml_settings['products_sync_order'] = 1;
299
300 update_option( '_wcml_settings', $wcml_settings );
301 }
302
303 public function upgrade_3_5_4() {
304 flush_rewrite_rules();
305 }
306
307 public function upgrade_3_6() {
308 $wcml_settings = get_option( '_wcml_settings' );
309
310 $wcml_settings['display_custom_prices'] = 0;
311 $wcml_settings['currency_switcher_product_visibility'] = 1;
312
313 update_option( '_wcml_settings', $wcml_settings );
314 }
315
316 public function upgrade_3_7() {
317 global $woocommerce_wpml, $wpdb;
318
319 $woocommerce_permalinks = maybe_unserialize( get_option( 'woocommerce_permalinks' ) );
320
321 if ( is_array( $woocommerce_permalinks ) ) {
322 foreach ( $woocommerce_permalinks as $base_key => $base ) {
323
324 $base_key = trim( $base_key, '/' );
325
326 if ( $base ) {
327 $taxonomy = false;
328
329 switch ( $base_key ) {
330 case 'category_base':
331 $taxonomy = 'product_cat';
332 break;
333 case 'tag_base':
334 $taxonomy = 'product_tag';
335 break;
336 case 'attribute_base':
337 $taxonomy = 'attribute';
338 break;
339 }
340
341 if ( $taxonomy ) {
342 $wpdb->update(
343 $wpdb->prefix . 'icl_strings',
344 [
345 'context' => 'WordPress',
346 'name' => sprintf( 'URL %s tax slug', $taxonomy ),
347 ],
348 [
349 'context' => sprintf( 'URL %s slugs - %s', $taxonomy, $base ),
350 'name' => sprintf( 'Url %s slug: %s', $taxonomy, $base ),
351 ]
352 );
353
354 }
355 }
356 }
357 }
358
359 $endpoint_keys = [
360 'order-pay',
361 'order-received',
362 'view-order',
363 'edit-account',
364 'edit-address',
365 'lost-password',
366 'customer-logout',
367 'add-payment-method',
368 ];
369
370 foreach ( $endpoint_keys as $endpoint_key ) {
371 $wpdb->query(
372 $wpdb->prepare(
373 "UPDATE {$wpdb->prefix}icl_strings
374 SET context = %s, name = %s
375 WHERE context = 'WordPress' AND name = %s",
376 WCML_Url_Translation::WC_STRING_CONTEXT,
377 $endpoint_key,
378 'Endpoint slug: ' . $endpoint_key
379 )
380 );
381
382 $string_id = $wpdb->get_var( $wpdb->prepare( "SELECT id FROM {$wpdb->prefix}icl_strings WHERE context = %s AND name = %s", WCML_Url_Translation::WC_STRING_CONTEXT, $endpoint_key ) );
383
384 if ( $string_id ) {
385 $wpdb->query(
386 $wpdb->prepare(
387 "UPDATE {$wpdb->prefix}icl_strings
388 SET domain_name_context_md5 = %s
389 WHERE id = %d",
390 md5( $endpoint_key, WCML_Url_Translation::WC_STRING_CONTEXT ),
391 $string_id
392 )
393 );
394 }
395 }
396
397 if ( ! isset( $woocommerce_wpml->terms ) ) {
398 global $sitepress;
399 $woocommerce_wpml->terms = new WCML_Terms( $woocommerce_wpml, $sitepress, $wpdb );
400 }
401 $woocommerce_wpml->terms->check_if_sync_terms_needed();
402
403 $wcml_settings = get_option( '_wcml_settings' );
404
405 $wcml_settings['sync_taxonomies_checked'] = 1;
406
407 update_option( '_wcml_settings', $wcml_settings );
408
409 $bookable_resources = $wpdb->get_results( "SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type = 'post_bookable_resource' AND source_language_code IS NOT NULL" );
410
411 foreach ( $bookable_resources as $bookable_resource ) {
412 update_post_meta( $bookable_resource->element_id, 'wcml_is_translated', true );
413 }
414
415 $bookable_persons = $wpdb->get_results( "SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type = 'post_bookable_person' AND source_language_code IS NOT NULL" );
416
417 foreach ( $bookable_persons as $bookable_person ) {
418 update_post_meta( $bookable_person->element_id, 'wcml_is_translated', true );
419 }
420 }
421
422 public function upgrade_3_7_3() {
423 global $sitepress;
424
425 $active_languages = $sitepress->get_active_languages();
426 $current_language = $sitepress->get_current_language();
427
428 foreach ( $active_languages as $lang ) {
429 $sitepress->switch_lang( $lang['code'] );
430
431 $product_cats = get_terms(
432 'product_cat',
433 [
434 'hide_empty' => false,
435 'fields' => 'id=>parent',
436 ]
437 );
438
439 _wc_term_recount( $product_cats, get_taxonomy( 'product_cat' ), true, false );
440
441 $product_tags = get_terms(
442 'product_tag',
443 [
444 'hide_empty' => false,
445 'fields' => 'id=>parent',
446 ]
447 );
448
449 _wc_term_recount( $product_tags, get_taxonomy( 'product_tag' ), true, false );
450 }
451
452 $sitepress->switch_lang( $current_language );
453 }
454
455 public function upgrade_3_7_11() {
456 $wcml_settings = get_option( '_wcml_settings' );
457 $wcml_settings['dismiss_doc_main'] = 1;
458 update_option( '_wcml_settings', $wcml_settings );
459 }
460
461 public function upgrade_3_8() {
462 $wcml_settings = get_option( '_wcml_settings' );
463 $wcml_settings['set_up_wizard_run'] = 1;
464
465 if ( isset( $wcml_settings['attributes_settings'] ) ) {
466 $attributes_settings = $wcml_settings['attributes_settings'];
467 foreach ( $attributes_settings as $name => $value ) {
468 if ( ! WCTaxonomies::isProductAttribute( $name ) ) {
469 unset( $wcml_settings['attributes_settings'] [ $name ] );
470 $wcml_settings['attributes_settings'] [ WCTaxonomies::TAXONOMY_PREFIX_ATTRIBUTE . $name ] = $value;
471 }
472 }
473 }
474
475 update_option( '_wcml_settings', $wcml_settings );
476 }
477
478 public function upgrade_3_9() {
479 global $wpdb;
480
481 $meta_keys_to_fix = [
482 '_price',
483 '_regular_price',
484 '_sale_price',
485 '_sku',
486 ];
487
488 $sql = "
489 UPDATE {$wpdb->postmeta}
490 SET meta_value = ''
491 WHERE meta_key IN (" . DB::prepareIn( $meta_keys_to_fix ) . ")
492 AND meta_value IS NULL";
493
494 $wpdb->query( $sql );
495 }
496
497 public function upgrade_3_9_1() {
498 global $wpdb, $sitepress;
499
500 $results = $wpdb->get_results(
501 "
502 SELECT p.ID, t.trid, t.element_type
503 FROM {$wpdb->posts} p
504 JOIN {$wpdb->prefix}icl_translations t ON t.element_id = p.ID AND t.element_type IN ('post_product', 'post_product_variation')
505 WHERE p.post_type in ('product', 'product_variation') AND t.source_language_code IS NULL
506 "
507 );
508
509 foreach ( $results as $product ) {
510 if ( get_post_meta( $product->ID, '_manage_stock', true ) === 'yes' ) {
511 $translations = $sitepress->get_element_translations( $product->trid, $product->element_type );
512
513 $min_stock = false;
514
515 foreach ( $translations as $translation ) {
516 $stock = get_post_meta( $translation->element_id, '_stock', true );
517 if ( ! $min_stock || $stock < $min_stock ) {
518 $min_stock = $stock;
519 }
520 }
521
522 foreach ( $translations as $translation ) {
523 update_post_meta( $translation->element_id, '_stock', $min_stock );
524 }
525 }
526 }
527 }
528
529 public function upgrade_4_0() {
530 $wcml_settings = get_option( '_wcml_settings' );
531 $wcml_settings['dismiss_tm_warning'] = 0;
532 $wcml_settings['cart_sync']['lang_switch'] = WCML_CART_SYNC;
533 $wcml_settings['cart_sync']['currency_switch'] = WCML_CART_SYNC;
534
535 update_option( '_wcml_settings', $wcml_settings );
536
537 }
538
539 public function upgrade_4_1_0() {
540 global $wpdb;
541
542 if ( ! class_exists( 'WooCommerce' ) ) {
543 update_option( '_wcml_4_1_0_migration_required', true );
544 } else {
545 $results = $wpdb->get_results(
546 "
547 SELECT *
548 FROM {$wpdb->postmeta}
549 WHERE meta_key LIKE '\\_price\\_%' OR meta_key LIKE '\\_regular_price\\_%' OR ( meta_key LIKE '\\_sale_price\\_%' AND meta_key NOT LIKE '\\_sale\\_price\\_dates%' )
550 "
551 );
552
553 foreach ( $results as $price ) {
554 $formatted_price = wc_format_decimal( $price->meta_value );
555 update_post_meta( $price->post_id, $price->meta_key, $formatted_price );
556
557 if ( 'product_variation' === get_post_type( $price->post_id ) ) {
558 delete_transient( 'wc_var_prices_' . wp_get_post_parent_id( $price->post_id ) );
559 }
560 }
561
562 $wcml_settings = get_option( '_wcml_settings' );
563
564 if (
565 isset( $wcml_settings['currency_switcher_style'] ) &&
566 'list' === $wcml_settings['currency_switcher_style']
567 ) {
568 if ( 'horizontal' === $wcml_settings['wcml_curr_sel_orientation'] ) {
569 $switcher_style = 'wcml-horizontal-list';
570 } else {
571 $switcher_style = 'wcml-vertical-list';
572 }
573 } else {
574 $switcher_style = 'wcml-dropdown';
575 }
576
577 $wcml_settings['currency_switchers']['product'] = [
578 'switcher_style' => $switcher_style,
579 'template' => $wcml_settings['wcml_curr_template'] ?? '',
580 'widget_title' => '',
581 'color_scheme' => [
582 'font_current_normal' => '',
583 'font_current_hover' => '',
584 'background_current_normal' => '',
585 'background_current_hover' => '',
586 'font_other_normal' => '',
587 'font_other_hover' => '',
588 'background_other_normal' => '',
589 'background_other_hover' => '',
590 'border_normal' => '',
591 ],
592 ];
593
594 $wcml_settings['currency_switcher_additional_css'] = '';
595 update_option( '_wcml_settings', $wcml_settings );
596 }
597 }
598
599 public function upgrade_4_2_0() {
600 $wcml_settings = get_option( '_wcml_settings' );
601 $wcml_settings['dismiss_cart_warning'] = 0;
602
603 update_option( '_wcml_settings', $wcml_settings );
604 }
605
606 private function upgrade_4_2_2() {
607 $user = new WP_User( 'admin' );
608 if ( $user->exists() && ! is_super_admin( $user->ID ) ) {
609 $user->remove_cap( 'wpml_manage_woocommerce_multilingual' );
610 if ( ! in_array( 'shop_manager', $user->roles, true ) ) {
611 $user->remove_cap( 'wpml_operate_woocommerce_multilingual' );
612 }
613 }
614 }
615
616 private function upgrade_4_2_7() {
617 $wcml_settings = get_option( '_wcml_settings' );
618 if ( 'yahoo' === $wcml_settings['multi_currency']['exchange_rates']['service'] ) {
619 $wcml_settings['multi_currency']['exchange_rates']['service'] = 'fixerio';
620 update_option( '_wcml_settings', $wcml_settings );
621 }
622 }
623
624 private function upgrade_4_2_10() {
625 global $wpdb;
626 if ( defined( 'WC_BOOKINGS_VERSION' ) && version_compare( WC_BOOKINGS_VERSION, '1.10.9', '>=' ) ) {
627 $results = $wpdb->get_results(
628 "
629 SELECT *
630 FROM {$wpdb->postmeta}
631 WHERE meta_key LIKE '\\_wc_booking_base_cost\\_%' )
632 "
633 );
634
635 foreach ( $results as $price ) {
636 $base_cost_price = $price->meta_value;
637 $block_cost_field_key = str_replace( 'base', 'block', $price->meta_key );
638 update_post_meta( $price->post_id, $block_cost_field_key, $base_cost_price );
639 }
640 }
641 }
642
643 private function upgrade_4_2_11() {
644 global $wpdb;
645
646 $wpdb->query(
647 "UPDATE {$wpdb->prefix}woocommerce_order_itemmeta
648 SET meta_key = '_wcml_converted_subtotal'
649 WHERE meta_key = 'wcml_converted_subtotal'"
650 );
651
652 $wpdb->query(
653 "UPDATE {$wpdb->prefix}woocommerce_order_itemmeta
654 SET meta_key = '_wcml_converted_total'
655 WHERE meta_key = 'wcml_converted_total'"
656 );
657
658 WCML_Install::insert_default_categories();
659 }
660
661 private function upgrade_4_3_0() {
662 $wcml_settings = get_option( '_wcml_settings' );
663 if (
664 WCML_MULTI_CURRENCIES_INDEPENDENT === $wcml_settings['enable_multi_currency'] &&
665 isset( $wcml_settings['multi_currency']['exchange_rates']['service'] ) &&
666 'fixierio' === $wcml_settings['multi_currency']['exchange_rates']['service']
667 ) {
668 $wcml_settings['multi_currency']['exchange_rates']['service'] = 'fixerio';
669 update_option( '_wcml_settings', $wcml_settings );
670
671 $announcement_url = 'https://github.com/fixerAPI/fixer#readme';
672 $api_key_url = 'https://fixer.io/dashboard';
673 $announcement_link = '<a href="' . $announcement_url . '" target="_blank">' . __( 'important change about this service', 'woocommerce-multilingual' ) . '</a>';
674 $fixer_api_key_link = '<a href="' . $api_key_url . '" target="_blank">' . __( 'Fixer.io API key', 'woocommerce-multilingual' ) . '</a>';
675 $fixerio_name = '<strong>Fixer.io</strong>';
676 $mc_settings_link = '<a href="' . \WCML\Utilities\AdminUrl::getMultiCurrencyTab() . '">' . __( 'multicurrency settings page', 'woocommerce-multilingual' ) . '</a>';
677
678 // translators: 1: Fixer.io, 2: Announcement link.
679 $message = sprintf( __( 'Your site uses %1$s to automatically calculate prices in the secondary currency. There is an %2$s effective June 1st, 2018.', 'woocommerce-multilingual' ), $fixerio_name, $announcement_link );
680
681 $message .= '<br />';
682 // translators: 1: Mulicurrency tab link, 2: Fixer.io API key.
683 $message .= sprintf( __( 'Please go to the %1$s and fill in your %2$s.', 'woocommerce-multilingual' ), $mc_settings_link, $fixer_api_key_link );
684
685 $notice = new WPML_Notice( 'wcml-fixerio-api-key-required', $message, 'wcml-save-multi-currency-options' );
686 $notice->set_css_class_types( 'warning' );
687 $notice->set_dismissible( true );
688 $wpml_admin_notices = wpml_get_admin_notices();
689 $wpml_admin_notices->add_notice( $notice );
690 }
691 }
692
693 private function upgrade_4_3_4() {
694 global $wpdb;
695
696 $wpdb->query( "DELETE FROM {$wpdb->prefix}icl_translations WHERE `element_id` IN ( SELECT ID FROM {$wpdb->prefix}posts WHERE `guid` LIKE '%attachment_id%' ) " );
697 $wpdb->query( "DELETE FROM {$wpdb->prefix}postmeta WHERE `post_id` IN ( SELECT ID FROM {$wpdb->prefix}posts WHERE `guid` LIKE '%attachment_id%' ) " );
698 $wpdb->query( "DELETE FROM {$wpdb->prefix}posts WHERE `guid` LIKE '%attachment_id%'" );
699 }
700
701 private function upgrade_4_3_5() {
702 if ( class_exists( 'WC_Product_Bundle' ) && function_exists( 'WC_PB' ) ) {
703 global $wpdb;
704 $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_bundled_itemmeta WHERE `meta_key` LIKE 'translation_item_id_of_%' AND `meta_value` IN ( SELECT bundled_item_id FROM {$wpdb->prefix}woocommerce_bundled_items WHERE `product_id` = 0 AND `bundle_id` = 0 ) " );
705 $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_bundled_items WHERE `product_id` = 0 AND `bundle_id` = 0 " );
706 $not_existing_items = $wpdb->get_col( "SELECT m.`meta_id` FROM {$wpdb->prefix}woocommerce_bundled_itemmeta AS m LEFT JOIN {$wpdb->prefix}woocommerce_bundled_items as i ON m.meta_value = i.bundled_item_id WHERE m.`meta_key` LIKE 'translation_item_id_of_%' AND i.`bundled_item_id` IS NULL" );
707 $wpdb->query( "DELETE FROM {$wpdb->prefix}woocommerce_bundled_itemmeta WHERE `meta_id` IN (" . DB::prepareIn( $not_existing_items ) . ')' );
708 }
709 }
710
711 private function upgrade_4_4_1() {
712 global $sitepress, $woocommerce_wpml;
713
714 if ( ! $woocommerce_wpml->is_wpml_prior_4_2() ) {
715 $wcml_settings = get_option( '_wcml_settings' );
716 $tm_settings = $sitepress->get_setting( 'translation-management', [] );
717
718 if ( $wcml_settings['trnsl_interface'] ) {
719 $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_FOR_POST_TYPE_USE_NATIVE ]['product'] = false;
720 } else {
721 $tm_settings[ WPML_TM_Post_Edit_TM_Editor_Mode::TM_KEY_FOR_POST_TYPE_USE_NATIVE ]['product'] = true;
722 }
723
724 $sitepress->set_setting( 'translation-management', $tm_settings, true );
725 }
726 }
727
728
729 private function upgrade_4_4_3() {
730 if ( class_exists( 'WC_SwatchesPlugin' ) ) {
731 global $wpdb, $sitepress, $wpml_post_translations, $woocommerce_wpml;
732
733 $variation_sp = new WCML_Variation_Swatches_And_Photos( $woocommerce_wpml );
734 $original_products = $wpdb->get_results(
735 "
736 SELECT element_id
737 FROM {$wpdb->prefix}icl_translations
738 WHERE element_type = 'post_product' AND source_language_code IS NULL"
739 );
740
741 $current_language = $sitepress->get_current_language();
742
743 foreach ( $original_products as $product ) {
744 $sitepress->switch_lang( $wpml_post_translations->get_element_lang_code( $product->element_id ) );
745
746 $translations = $wpml_post_translations->get_element_translations( $product->element_id, false, true );
747 foreach ( $translations as $translation ) {
748 $variation_sp->sync_variation_swatches_and_photos( $product->element_id, $translation, false );
749 }
750 }
751
752 $sitepress->switch_lang( $current_language );
753 }
754 }
755
756 private function upgrade_4_7_0() {
757 global $wpdb;
758
759 $wpdb->query(
760 "UPDATE {$wpdb->prefix}icl_strings
761 SET `context` = 'admin_texts_woocommerce_gateways',
762 `domain_name_context_md5` = MD5( CONCAT( 'admin_texts_woocommerce_gateways', `name`, `gettext_context` ) )
763 WHERE `context` = 'woocommerce' AND `name` LIKE '%_gateway_title'"
764 );
765 $wpdb->query(
766 "UPDATE {$wpdb->prefix}icl_strings
767 SET `context` = 'admin_texts_woocommerce_gateways',
768 `domain_name_context_md5` = MD5( CONCAT( 'admin_texts_woocommerce_gateways', `name`, `gettext_context` ) )
769 WHERE `context` = 'woocommerce' AND `name` LIKE '%_gateway_description'"
770 );
771 $wpdb->query(
772 "UPDATE {$wpdb->prefix}icl_strings
773 SET `context` = 'admin_texts_woocommerce_gateways',
774 `domain_name_context_md5` = MD5( CONCAT( 'admin_texts_woocommerce_gateways', `name`, `gettext_context` ) )
775 WHERE `context` = 'woocommerce' AND `name` LIKE '%_gateway_instructions'"
776 );
777 }
778
779 private function upgrade_4_7_3() {
780 delete_option( 'wcml_currency_switcher_template_objects' );
781 }
782
783 private function upgrade_4_7_6() {
784 global $wpdb;
785
786 $wpdb->query(
787 "UPDATE {$wpdb->prefix}icl_strings
788 SET `context` = 'admin_texts_woocommerce_shipping',
789 `domain_name_context_md5` = MD5( CONCAT( 'admin_texts_woocommerce_shipping', `name`, `gettext_context` ) )
790 WHERE `context` = 'woocommerce' AND `name` LIKE '%_shipping_method_title'"
791 );
792 }
793
794 private function upgrade_4_7_8() {
795 $emailOptions = [
796 'woocommerce_new_order_settings',
797 'woocommerce_cancelled_order_settings',
798 'woocommerce_failed_order_settings',
799 'woocommerce_customer_on_hold_order_settings',
800 'woocommerce_customer_processing_order_settings',
801 'woocommerce_customer_completed_order_settings',
802 'woocommerce_customer_refunded_order_settings',
803 'woocommerce_customer_invoice_settings',
804 'woocommerce_customer_note_settings',
805 'woocommerce_customer_reset_password_settings',
806 'woocommerce_customer_new_account_settings'
807 ];
808
809
810 foreach ( $emailOptions as $emailOption ) {
811
812 $emailSettings = get_option( $emailOption );
813
814 if ( isset( $emailSettings['additional_content'] ) && $emailSettings['additional_content'] ) {
815 $domain = 'admin_texts_' . $emailOption;
816 $name = '[' . $emailOption . ']additional_content';
817
818 icl_register_string( $domain, $name, $emailSettings['additional_content'], false, '' );
819 }
820 }
821 }
822
823 private function upgrade_4_10_0() {
824 $wcml_settings = get_option( '_wcml_settings' );
825 if ( WCML_MULTI_CURRENCIES_INDEPENDENT === $wcml_settings['enable_multi_currency'] ) {
826 McSettings::setMode( McSettings::MODE_BY_LANGUAGE );
827 }
828 }
829
830 private function upgrade_4_11_0() {
831 global $sitepress;
832
833 WCML_Install::set_language_to_existing_orders( $sitepress->get_default_language() );
834 }
835
836 private function upgrade_4_12_0() {
837 wp_schedule_single_event( time() + 10, 'generate_category_lookup_table' );
838 }
839
840 private function upgrade_5_0_0() {
841 delete_transient( WCML_Payment_Gateway_PayPal_V2::BEARER_TOKEN_TRANSIENT );
842 }
843
844 private function upgrade_5_3_0() {
845 if (
846 LookupTableFactory::hasFeature() &&
847 ! wc_get_container()->get( LookupDataStore::class )->regeneration_is_in_progress()
848 ) {
849 wc_get_container()->get( DataRegenerator::class )->initiate_regeneration();
850 }
851
852 $adminNotices = $this->get_wpml_admin_notices();
853
854 if ( $adminNotices ) {
855 $adminNotices->remove_notice( 'wcml-admin-notices', 'hpos-sync-disabled' );
856 }
857 }
858
859 private function get_wpml_admin_notices() {
860 if ( function_exists( 'wpml_get_admin_notices' ) ) {
861 return wpml_get_admin_notices();
862 } elseif ( function_exists( 'wcml_wpml_get_admin_notices' ) ) {
863 return wcml_wpml_get_admin_notices();
864 }
865
866 return null;
867 }
868
869 private function upgrade_5_4_1() {
870 $this->fixture_5_4_1_all_products_screen_set_languages_column_visible();
871 }
872
873 private function fixture_5_4_1_all_products_screen_set_languages_column_visible() {
874 if ( isStandAlone() ) {
875 return;
876 }
877
878 $hasTooManyLanguages = count( (array) getSitePress()->get_active_languages() ) > 4;
879
880 if ( $hasTooManyLanguages ) {
881 return;
882 }
883
884 $args = [
885 'capability__in' => [ 'edit_products' ],
886 ];
887
888 $users = get_users( $args );
889
890 foreach ( $users as $user ) {
891 $hiddenColumnsList = get_user_meta( $user->ID, \WCML\API\VendorAddon\Hooks::COLUMN_USER_OPTION, true );
892
893 if ( is_array( $hiddenColumnsList ) ) {
894 $columnKeyToRemove = array_search( 'icl_translations', $hiddenColumnsList, true );
895
896 if ( false !== $columnKeyToRemove ) {
897 unset( $hiddenColumnsList[ $columnKeyToRemove ] );
898
899 update_user_meta( $user->ID, \WCML\API\VendorAddon\Hooks::COLUMN_USER_OPTION, $hiddenColumnsList );
900 }
901 }
902 }
903 }
904
905 private function upgrade_5_4_4() {
906 \WCML_Capabilities::set_up_capabilities();
907 }
908
909 private function upgrade_5_5_2() {
910 delete_option( 'wcml_currency_switcher_template_objects' );
911 }
912 }
913