WooCommerce Multilingual – run WooCommerce with WPML - Version 3.7.12

Version Description

  • Fixed a bug that made the shop pages return 404 errors on WordPress 4.5
  • Fixed warnings caused by terms translated before the WooCommerce Multilingual activation
  • Bug fix: WooCommerce Multilingual locales for secondary languages were not loaded correctly
Download this release

Release Info

Developer mihaimihai
Plugin Icon 128x128 WooCommerce Multilingual – run WooCommerce with WPML
Version 3.7.12
Comparing to
See all releases

Code changes from version 3.7.11 to 3.7.12

composer.lock ADDED
@@ -0,0 +1,225 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_readme": [
3
+ "This file locks the dependencies of your project to a known state",
4
+ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
5
+ "This file is @generated automatically"
6
+ ],
7
+ "hash": "56384f3d83099ea22ec2ed3a83226e6a",
8
+ "content-hash": "c1e9907742d9eb4aaa40d6eb6325129d",
9
+ "packages": [
10
+ {
11
+ "name": "composer/installers",
12
+ "version": "v1.0.23",
13
+ "source": {
14
+ "type": "git",
15
+ "url": "https://github.com/composer/installers.git",
16
+ "reference": "6213d900e92647831f7a406d5c530ea1f3d4360e"
17
+ },
18
+ "dist": {
19
+ "type": "zip",
20
+ "url": "https://api.github.com/repos/composer/installers/zipball/6213d900e92647831f7a406d5c530ea1f3d4360e",
21
+ "reference": "6213d900e92647831f7a406d5c530ea1f3d4360e",
22
+ "shasum": ""
23
+ },
24
+ "require": {
25
+ "composer-plugin-api": "^1.0"
26
+ },
27
+ "replace": {
28
+ "roundcube/plugin-installer": "*",
29
+ "shama/baton": "*"
30
+ },
31
+ "require-dev": {
32
+ "composer/composer": "1.0.*@dev",
33
+ "phpunit/phpunit": "4.1.*"
34
+ },
35
+ "type": "composer-plugin",
36
+ "extra": {
37
+ "class": "Composer\\Installers\\Plugin",
38
+ "branch-alias": {
39
+ "dev-master": "1.0-dev"
40
+ }
41
+ },
42
+ "autoload": {
43
+ "psr-0": {
44
+ "Composer\\Installers\\": "src/"
45
+ }
46
+ },
47
+ "notification-url": "https://packagist.org/downloads/",
48
+ "license": [
49
+ "MIT"
50
+ ],
51
+ "authors": [
52
+ {
53
+ "name": "Kyle Robinson Young",
54
+ "email": "kyle@dontkry.com",
55
+ "homepage": "https://github.com/shama"
56
+ }
57
+ ],
58
+ "description": "A multi-framework Composer library installer",
59
+ "homepage": "http://composer.github.com/installers/",
60
+ "keywords": [
61
+ "Craft",
62
+ "Dolibarr",
63
+ "Hurad",
64
+ "MODX Evo",
65
+ "OXID",
66
+ "SMF",
67
+ "Thelia",
68
+ "WolfCMS",
69
+ "agl",
70
+ "aimeos",
71
+ "annotatecms",
72
+ "bitrix",
73
+ "cakephp",
74
+ "chef",
75
+ "codeigniter",
76
+ "concrete5",
77
+ "croogo",
78
+ "dokuwiki",
79
+ "drupal",
80
+ "elgg",
81
+ "fuelphp",
82
+ "grav",
83
+ "installer",
84
+ "joomla",
85
+ "kohana",
86
+ "laravel",
87
+ "lithium",
88
+ "magento",
89
+ "mako",
90
+ "mediawiki",
91
+ "modulework",
92
+ "moodle",
93
+ "phpbb",
94
+ "piwik",
95
+ "ppi",
96
+ "puppet",
97
+ "roundcube",
98
+ "shopware",
99
+ "silverstripe",
100
+ "symfony",
101
+ "typo3",
102
+ "wordpress",
103
+ "zend",
104
+ "zikula"
105
+ ],
106
+ "time": "2016-01-27 12:54:22"
107
+ },
108
+ {
109
+ "name": "otgs/installer",
110
+ "version": "1.7.6",
111
+ "source": {
112
+ "type": "git",
113
+ "url": "ssh://git@git.onthegosystems.com:10022/installer/installer.git",
114
+ "reference": "61f0d3178e84f9c96cd8580a5e28d30a84ff4e5a"
115
+ },
116
+ "require": {
117
+ "composer/installers": "~1.0",
118
+ "php": ">=5.2.0"
119
+ },
120
+ "require-dev": {
121
+ "phpunit/phpunit": "~4.5"
122
+ },
123
+ "type": "wordpress-plugin",
124
+ "extra": {
125
+ "branch-alias": {
126
+ "dev-master": "1.6.x-dev",
127
+ "dev-develop": "1.6.x-dev"
128
+ }
129
+ },
130
+ "scripts": {
131
+ "test": [
132
+ "phpunit"
133
+ ]
134
+ },
135
+ "license": [
136
+ "GPL-2.0"
137
+ ],
138
+ "authors": [
139
+ {
140
+ "name": "Mihai Grigori",
141
+ "email": "mihai@wpml.org",
142
+ "homepage": "http://www.wp-types.com"
143
+ }
144
+ ],
145
+ "description": "Installs and updates WPML and Toolset dependencies automatically",
146
+ "homepage": "https://git.onthegosystems.com/installer/installer",
147
+ "keywords": [
148
+ "install",
149
+ "plugins",
150
+ "update",
151
+ "utils"
152
+ ],
153
+ "time": "2016-02-23 13:04:37"
154
+ },
155
+ {
156
+ "name": "wpml/commons",
157
+ "version": "dev-develop",
158
+ "source": {
159
+ "type": "git",
160
+ "url": "ssh://git@git.onthegosystems.com:10022/wpml/wpml-commons.git",
161
+ "reference": "3f19b7bbd079faaf2ca7fedecf610d64deb847d0"
162
+ },
163
+ "require": {
164
+ "php": ">=5.2.0"
165
+ },
166
+ "require-dev": {
167
+ "phpunit/phpunit": "~4.5"
168
+ },
169
+ "type": "library",
170
+ "extra": {
171
+ "branch-alias": {
172
+ "dev-master": "1.0.x-dev",
173
+ "dev-develop": "1.0.x-dev"
174
+ }
175
+ },
176
+ "autoload": {
177
+ "classmap": [
178
+ "src/"
179
+ ]
180
+ },
181
+ "scripts": {
182
+ "test": [
183
+ "phpunit"
184
+ ]
185
+ },
186
+ "license": [
187
+ "GPL-2.0"
188
+ ],
189
+ "authors": [
190
+ {
191
+ "name": "Andrea Sciamanna",
192
+ "email": "andrea.s@icanlocalize.com",
193
+ "homepage": "http://wpml.org"
194
+ },
195
+ {
196
+ "name": "Bruce Pearsons",
197
+ "email": "bruce.p@icanlocalize.com",
198
+ "homepage": "http://wpml.org"
199
+ },
200
+ {
201
+ "name": "Armin Braun",
202
+ "email": "armin.b@icanlocalize.com",
203
+ "homepage": "http://wpml.org"
204
+ }
205
+ ],
206
+ "description": "A set of libraries for WPML Plugins",
207
+ "homepage": "https://git.onthegosystems.com/wpml/wpml-commons",
208
+ "keywords": [
209
+ "auto-loader",
210
+ "twig-extensions"
211
+ ],
212
+ "time": "2016-01-15 12:51:10"
213
+ }
214
+ ],
215
+ "packages-dev": [],
216
+ "aliases": [],
217
+ "minimum-stability": "stable",
218
+ "stability-flags": {
219
+ "wpml/commons": 20
220
+ },
221
+ "prefer-stable": false,
222
+ "prefer-lowest": false,
223
+ "platform": [],
224
+ "platform-dev": []
225
+ }
inc/class-wcml-languages-upgrader.php CHANGED
@@ -26,7 +26,7 @@ class WCML_Languages_Upgrader{
26
 
27
  $locale = $sitepress->get_locale( $lang_code );
28
 
29
- if( $locale != 'en_US' && $this->has_available_update( $locale ) ){
30
 
31
  $wc_version = $wc_version ? $wc_version : WC_VERSION;
32
 
@@ -199,13 +199,14 @@ class WCML_Languages_Upgrader{
199
  *
200
  * @return bool
201
  */
202
- function has_available_update( $locale ) {
 
203
  $version = get_option( 'woocommerce_language_pack_version_'.$locale, array( '0', $locale ) );
204
 
205
  $notices = maybe_unserialize( get_option( 'wcml_translations_upgrade_notice' ) );
206
 
207
- if ( 'en_US' !== $locale && ( ! is_array( $version ) || version_compare( $version[0], WC_VERSION, '<' ) || $version[1] !== $locale ) ) {
208
- if ( $this->check_if_language_pack_exists( $locale ) ){
209
 
210
  if( !$notices || !in_array( $locale, $notices )){
211
  $notices[] = $locale;
@@ -217,7 +218,7 @@ class WCML_Languages_Upgrader{
217
  return true;
218
  } else {
219
  // Updated the woocommerce_language_pack_version to avoid searching translations for this release again
220
- update_option( 'woocommerce_language_pack_version_'.$locale, array( WC_VERSION, $locale ) );
221
  }
222
  }
223
 
@@ -230,9 +231,9 @@ class WCML_Languages_Upgrader{
230
  *
231
  * @return bool
232
  */
233
- function check_if_language_pack_exists( $locale ) {
234
 
235
- $response = wp_safe_remote_get( $this->get_language_pack_uri( $locale ), array( 'timeout' => 60 ) );
236
 
237
  if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && $response['body'] != '404 File not found' ) {
238
  return true;
26
 
27
  $locale = $sitepress->get_locale( $lang_code );
28
 
29
+ if( $locale != 'en_US' && $this->has_available_update( $locale, $wc_version ) ){
30
 
31
  $wc_version = $wc_version ? $wc_version : WC_VERSION;
32
 
199
  *
200
  * @return bool
201
  */
202
+ function has_available_update( $locale, $wc_version = false ) {
203
+ $wc_version = $wc_version ? $wc_version : WC_VERSION;
204
  $version = get_option( 'woocommerce_language_pack_version_'.$locale, array( '0', $locale ) );
205
 
206
  $notices = maybe_unserialize( get_option( 'wcml_translations_upgrade_notice' ) );
207
 
208
+ if ( 'en_US' !== $locale && ( ! is_array( $version ) || version_compare( $version[0], $wc_version, '<' ) || $version[1] !== $locale ) ) {
209
+ if ( $this->check_if_language_pack_exists( $locale, $wc_version ) ){
210
 
211
  if( !$notices || !in_array( $locale, $notices )){
212
  $notices[] = $locale;
218
  return true;
219
  } else {
220
  // Updated the woocommerce_language_pack_version to avoid searching translations for this release again
221
+ update_option( 'woocommerce_language_pack_version_'.$locale, array( $wc_version, $locale ) );
222
  }
223
  }
224
 
231
  *
232
  * @return bool
233
  */
234
+ function check_if_language_pack_exists( $locale, $wc_version ) {
235
 
236
+ $response = wp_safe_remote_get( $this->get_language_pack_uri( $locale, $wc_version ), array( 'timeout' => 60 ) );
237
 
238
  if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && $response['body'] != '404 File not found' ) {
239
  return true;
inc/products.class.php CHANGED
@@ -75,7 +75,7 @@ class WCML_Products{
75
  add_action( 'woocommerce_email', array( $this, 'woocommerce_email_refresh_text_domain' ) );
76
  add_action( 'wp_ajax_woocommerce_update_shipping_method', array( $this, 'wcml_refresh_text_domain' ), 9 );
77
  add_action( 'wp_ajax_nopriv_woocommerce_update_shipping_method', array( $this, 'wcml_refresh_text_domain' ), 9 );
78
- add_filter( 'wpml_link_to_translation', array( $this, '_filter_link_to_translation' ), 100, 2 );
79
 
80
  add_filter( 'woocommerce_upsell_crosssell_search_products', array( $this, 'filter_woocommerce_upsell_crosssell_posts_by_language' ) );
81
 
@@ -1309,7 +1309,7 @@ class WCML_Products{
1309
  }
1310
 
1311
 
1312
- function _filter_link_to_translation( $link, $post_id ){
1313
  global $woocommerce_wpml;
1314
 
1315
  if( $woocommerce_wpml->settings[ 'trnsl_interface' ] &&
@@ -1321,9 +1321,13 @@ class WCML_Products{
1321
 
1322
  if( empty( $post_id ) && isset( $_GET['post'] ) ){
1323
  $post_id = $_GET['post'];
 
 
 
 
1324
  }
1325
 
1326
- if( isset( $_GET[ 'post' ] ) || !$this->is_original_product( $post_id ) ){
1327
  $link = admin_url( 'admin.php?page=wpml-wcml&tab=products&prid='.$post_id );
1328
  }
1329
 
@@ -2857,7 +2861,7 @@ class WCML_Products{
2857
  $all_products_taxonomies = get_taxonomies( array( 'object_type' => array( 'product' ) ), 'objects' );
2858
 
2859
  foreach($all_products_taxonomies as $tax_key => $tax) {
2860
- if($tax_key == 'product_type' ) continue;
2861
 
2862
  $found = false;
2863
 
@@ -2981,7 +2985,14 @@ class WCML_Products{
2981
 
2982
  $new_id_obj = get_post( $new_id );
2983
  $new_slug = wp_unique_post_slug( sanitize_title( $new_id_obj->post_title ), $new_id, $post_to_duplicate->post_status, $post_to_duplicate->post_type, $new_id_obj->post_parent );
2984
- $wpdb->update( $wpdb->posts, array( 'post_name' => $new_slug, 'post_status' => $post_to_duplicate->post_status ), array( 'ID' => $new_id ) );
 
 
 
 
 
 
 
2985
 
2986
  do_action( 'wcml_after_duplicate_product' , $new_id, $post_to_duplicate );
2987
 
75
  add_action( 'woocommerce_email', array( $this, 'woocommerce_email_refresh_text_domain' ) );
76
  add_action( 'wp_ajax_woocommerce_update_shipping_method', array( $this, 'wcml_refresh_text_domain' ), 9 );
77
  add_action( 'wp_ajax_nopriv_woocommerce_update_shipping_method', array( $this, 'wcml_refresh_text_domain' ), 9 );
78
+ add_filter( 'wpml_link_to_translation', array( $this, '_filter_link_to_translation' ), 100, 3 );
79
 
80
  add_filter( 'woocommerce_upsell_crosssell_search_products', array( $this, 'filter_woocommerce_upsell_crosssell_posts_by_language' ) );
81
 
1309
  }
1310
 
1311
 
1312
+ function _filter_link_to_translation( $link, $post_id, $lang ){
1313
  global $woocommerce_wpml;
1314
 
1315
  if( $woocommerce_wpml->settings[ 'trnsl_interface' ] &&
1321
 
1322
  if( empty( $post_id ) && isset( $_GET['post'] ) ){
1323
  $post_id = $_GET['post'];
1324
+ $is_original_post = $this->is_original_product( $post_id );
1325
+ }else{
1326
+ $post_language = wpml_get_language_information($post_id);
1327
+ $is_original_post = $post_language['language_code'] == $lang;
1328
  }
1329
 
1330
+ if( isset( $_GET[ 'post' ] ) || !$is_original_post ){
1331
  $link = admin_url( 'admin.php?page=wpml-wcml&tab=products&prid='.$post_id );
1332
  }
1333
 
2861
  $all_products_taxonomies = get_taxonomies( array( 'object_type' => array( 'product' ) ), 'objects' );
2862
 
2863
  foreach($all_products_taxonomies as $tax_key => $tax) {
2864
+ if( substr( $tax_key, 0 , 3 ) != 'pa_' || !in_array( $tax_key, array( 'product_cat', 'product_tag', 'product_shipping_class' ) ) ) continue;
2865
 
2866
  $found = false;
2867
 
2985
 
2986
  $new_id_obj = get_post( $new_id );
2987
  $new_slug = wp_unique_post_slug( sanitize_title( $new_id_obj->post_title ), $new_id, $post_to_duplicate->post_status, $post_to_duplicate->post_type, $new_id_obj->post_parent );
2988
+ $wpdb->update(
2989
+ $wpdb->posts,
2990
+ array(
2991
+ 'post_name' => $new_slug,
2992
+ 'post_status' => 'draft'
2993
+ ),
2994
+ array( 'ID' => $new_id )
2995
+ );
2996
 
2997
  do_action( 'wcml_after_duplicate_product' , $new_id, $post_to_duplicate );
2998
 
inc/store-pages.class.php CHANGED
@@ -299,9 +299,7 @@ class WCML_Store_Pages{
299
  foreach ($miss_lang['codes'] as $mis_lang) {
300
  $args = array();
301
 
302
- unload_textdomain('woocommerce-multilingual');
303
- $sitepress->switch_lang($mis_lang);
304
- load_textdomain( 'woocommerce-multilingual', WCML_LOCALE_PATH . '/woocommerce-multilingual-' . $sitepress->get_locale( $mis_lang ) . '.mo' );
305
 
306
  foreach ($check_pages as $page) {
307
  $orig_id = get_option($page);
@@ -355,9 +353,7 @@ class WCML_Store_Pages{
355
 
356
  }
357
  }
358
- unload_textdomain('woocommerce-multilingual');
359
- $sitepress->switch_lang($default_language);
360
- load_textdomain( 'woocommerce-multilingual', WCML_LOCALE_PATH . '/woocommerce-multilingual-' . $sitepress->get_locale( $default_language ) . '.mo' );
361
  }
362
 
363
  wp_redirect(admin_url('admin.php?page=wpml-wcml')); exit;
@@ -576,11 +572,11 @@ class WCML_Store_Pages{
576
  $templates[] = $path.$file;
577
  }
578
 
579
- $template = locate_template( array_unique($templates) );
580
 
581
- if (!$template || WC_TEMPLATE_DEBUG_MODE) {
582
 
583
- $template = WC()->plugin_path() . '/templates/' . $file;
584
 
585
  }
586
 
299
  foreach ($miss_lang['codes'] as $mis_lang) {
300
  $args = array();
301
 
302
+ $woocommerce_wpml->switch_locale( $mis_lang );
 
 
303
 
304
  foreach ($check_pages as $page) {
305
  $orig_id = get_option($page);
353
 
354
  }
355
  }
356
+ $woocommerce_wpml->switch_locale();
 
 
357
  }
358
 
359
  wp_redirect(admin_url('admin.php?page=wpml-wcml')); exit;
572
  $templates[] = $path.$file;
573
  }
574
 
575
+ $loaded_template = locate_template( array_unique( $templates ) );
576
 
577
+ if ( $loaded_template ) {
578
 
579
+ $template = $loaded_template;
580
 
581
  }
582
 
inc/url-translation.class.php CHANGED
@@ -6,7 +6,13 @@ class WCML_Url_Translation {
6
  public $default_product_category_base;
7
  public $default_product_tag_base;
8
 
9
- function __construct() {
 
 
 
 
 
 
10
 
11
  $this->default_product_base = 'product';
12
  $this->default_product_category_base = 'product-category';
@@ -29,9 +35,8 @@ class WCML_Url_Translation {
29
  }
30
 
31
  function set_up() {
32
- global $woocommerce_wpml;
33
 
34
- if ( empty( $woocommerce_wpml->settings['url_translation_set_up'] ) ) {
35
 
36
  $this->clean_up_product_and_taxonomy_bases();
37
 
@@ -40,8 +45,8 @@ class WCML_Url_Translation {
40
 
41
  $this->register_product_and_taxonomy_bases();
42
 
43
- $woocommerce_wpml->settings['url_translation_set_up'] = 1;
44
- $woocommerce_wpml->update_settings();
45
  }
46
 
47
  }
@@ -140,12 +145,11 @@ class WCML_Url_Translation {
140
  } else {
141
 
142
  // force_product_slug_translation_on
143
- global $sitepress;
144
- $iclsettings = $sitepress->get_settings();
145
  if ( empty( $iclsettings['posts_slug_translation']['on'] ) || empty( $iclsettings['posts_slug_translation']['types']['product'] ) ) {
146
  $iclsettings['posts_slug_translation']['on'] = 1;
147
  $iclsettings['posts_slug_translation']['types']['product'] = 1;
148
- $sitepress->save_settings( $iclsettings );
149
  }
150
 
151
  $string = icl_get_string_id( $slug, $this->url_strings_context(), $this->url_string_name( 'product' ) );
@@ -170,7 +174,6 @@ class WCML_Url_Translation {
170
  }
171
 
172
  function register_product_and_taxonomy_bases( $value = false, $old_value = false ) {
173
- global $woocommerce_wpml;
174
 
175
  if( empty( $value ) ){
176
  $permalink_options = $this->wc_permalinks;
@@ -182,14 +185,14 @@ class WCML_Url_Translation {
182
  $product_base = !empty( $permalink_options['product_base'] ) ? trim( $permalink_options['product_base'], '/' ) : $this->default_product_base;
183
  $name = $this->url_string_name( 'product' );
184
 
185
- $string_language = $woocommerce_wpml->strings->get_string_language( $product_base, $this->url_strings_context(), $name );
186
  if( is_null($string_language) ){
187
  $string_language = '';
188
  }
189
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $name, $product_base, false, $string_language );
190
 
191
  if( isset($_POST['product_base_language'])){
192
- $woocommerce_wpml->strings->set_string_language( $product_base, $this->url_strings_context(), $name, $_POST['product_base_language']);
193
  }
194
 
195
  if ( $product_base == $this->default_product_base ) {
@@ -200,14 +203,14 @@ class WCML_Url_Translation {
200
  $category_base = !empty( $permalink_options['category_base'] ) ? $permalink_options['category_base'] : $this->default_product_category_base;
201
  $name = $this->url_string_name( 'product_cat' );
202
 
203
- $string_language = $woocommerce_wpml->strings->get_string_language( $category_base, $this->url_strings_context(), $name );
204
  if( is_null($string_language) ){
205
  $string_language = '';
206
  }
207
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $name, $category_base, false, $string_language );
208
 
209
  if( isset($_POST['category_base_language'])){
210
- $woocommerce_wpml->strings->set_string_language( $category_base, $this->url_strings_context(), $name, $_POST['category_base_language']);
211
  }
212
 
213
  if ( $category_base == $this->default_product_category_base ) {
@@ -218,14 +221,14 @@ class WCML_Url_Translation {
218
  $tag_base = !empty( $permalink_options['tag_base'] ) ? $permalink_options['tag_base'] : $this->default_product_tag_base;
219
  $name = $this->url_string_name( 'product_tag' );
220
 
221
- $string_language = $woocommerce_wpml->strings->get_string_language( $tag_base, $this->url_strings_context(), $name );
222
  if( is_null($string_language) ){
223
  $string_language = '';
224
  }
225
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $name, $tag_base, false, $string_language );
226
 
227
  if( isset($_POST['tag_base_language'])){
228
- $woocommerce_wpml->strings->set_string_language( $tag_base, $this->url_strings_context(), $name, $_POST['tag_base_language']);
229
  }
230
 
231
  if ( $tag_base == $this->default_product_tag_base ) {
@@ -236,14 +239,14 @@ class WCML_Url_Translation {
236
  if ( isset( $permalink_options['attribute_base'] ) && $permalink_options['attribute_base'] ) {
237
  $attr_base = trim( $permalink_options['attribute_base'], '/' );
238
 
239
- $string_language = $woocommerce_wpml->strings->get_string_language( $attr_base, $this->url_strings_context(), $name );
240
  if( is_null($string_language) ){
241
  $string_language = '';
242
  }
243
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $this->url_string_name( 'attribute' ), $attr_base, false, $string_language );
244
 
245
  if( isset($_POST['attribute_base_language'])){
246
- $woocommerce_wpml->strings->set_string_language( $attr_base, $this->url_strings_context(), $this->url_string_name( 'attribute' ), $_POST['attribute_base_language']);
247
  }
248
  }
249
 
@@ -251,13 +254,13 @@ class WCML_Url_Translation {
251
  }
252
 
253
  function add_default_slug_translations( $slug, $name ) {
254
- global $woocommerce_wpml, $sitepress, $wpdb;
255
 
256
  $string_id = icl_get_string_id( $slug, $this->url_strings_context(), $name );
257
 
258
  if ( WPML_SUPPORT_STRINGS_IN_DIFF_LANG ) {
259
 
260
- $string_language = $woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $name );
261
 
262
  // will use a filter in the future wpmlst-529
263
  $string_object = new WPML_ST_String( $string_id, $wpdb );
@@ -273,7 +276,7 @@ class WCML_Url_Translation {
273
  $string_translations[$s->language] = $s->status;
274
  }
275
 
276
- $languages = $sitepress->get_active_languages();
277
 
278
  foreach ( $languages as $language => $language_info ) {
279
 
@@ -282,7 +285,7 @@ class WCML_Url_Translation {
282
  // check if there's an existing translation
283
  if ( !isset( $string_translations[$language] ) ) {
284
 
285
- $slug_translation = $woocommerce_wpml->strings->get_translation_from_woocommerce_mo_file( $slug, $language, false );
286
 
287
  if ( $slug_translation ) {
288
  // add string translation
@@ -297,11 +300,10 @@ class WCML_Url_Translation {
297
  }
298
 
299
  function force_bases_in_strings_languages( $value ) {
300
- global $sitepress, $woocommerce_wpml;
301
 
302
- if( $value && $sitepress->get_current_language() != 'en' ) {
303
 
304
- remove_filter( 'gettext_with_context', array( $woocommerce_wpml->strings, 'category_base_in_strings_language' ), 99, 3 );
305
  $taxonomies = array(
306
  'product_cat' => array(
307
  'base' => 'category_base',
@@ -314,7 +316,7 @@ class WCML_Url_Translation {
314
  'default' => $this->default_product_tag_base
315
  ),
316
  );
317
- add_filter( 'gettext_with_context', array( $woocommerce_wpml->strings, 'category_base_in_strings_language' ), 99, 3 );
318
 
319
  foreach ( $taxonomies as $taxonomy => $taxonomy_details ) {
320
 
@@ -339,118 +341,120 @@ class WCML_Url_Translation {
339
  }
340
 
341
  function translate_bases_in_rewrite_rules( $value ) {
342
- global $sitepress, $sitepress_settings, $woocommerce_wpml;
343
-
344
- $taxonomies = array( 'product_cat', 'product_tag' );
345
-
346
- foreach ( $taxonomies as $taxonomy ) {
347
- $slug_details = $this->get_translated_tax_slug( $taxonomy );
348
-
349
- $string_language = $woocommerce_wpml->strings->get_string_language( $slug_details['slug'], $this->url_strings_context(), $this->url_string_name( $taxonomy ) );
350
- if ( $sitepress->get_current_language() == $string_language ) {
351
- continue;
352
- }
353
-
354
- if ( $slug_details ) {
355
-
356
- $slug_match = addslashes( ltrim($slug_details['slug'], '/') );
357
- $slug_translation_match = ltrim($slug_details['translated_slug'], '/');
358
-
359
- $buff_value = array();
360
- foreach ( (array)$value as $k => $v ) {
361
-
362
- if ( $slug_details['slug'] != $slug_details['translated_slug'] && preg_match( '#^[^/]*/?' . $slug_match . '/#', $k ) ) {
363
- $k = preg_replace( '#^([^/]*)(/?)' . $slug_match . '/#', '$1$2' . $slug_translation_match . '/', $k );
364
- }
365
-
366
- $buff_value[$k] = $v;
367
- }
368
- $value = $buff_value;
369
- unset( $buff_value );
370
- }
371
-
372
- }
373
-
374
- // handle attributes
375
- $wc_taxonomies = wc_get_attribute_taxonomies();
376
- $wc_taxonomies_wc_format = array();
377
- foreach ( $wc_taxonomies as $k => $v ) {
378
- $wc_taxonomies_wc_format[] = 'pa_' . $v->attribute_name;
379
- }
380
-
381
- foreach ( $wc_taxonomies_wc_format as $taxonomy ) {
382
- $taxonomy_obj = get_taxonomy( $taxonomy );
383
-
384
- if ( isset( $taxonomy_obj->rewrite['slug'] ) ) {
385
- $exp = explode( '/', trim( $taxonomy_obj->rewrite['slug'], '/' ) );
386
- $slug = join( '/', array_slice( $exp, 0, count( $exp ) - 1 ) );
387
- }
388
-
389
- if ( isset( $slug ) ) {
390
- $string_language = $woocommerce_wpml->strings->get_string_language($slug, $this->url_strings_context(), $this->url_string_name( 'attribute' ) );
391
-
392
- if ($sitepress->get_current_language() != $string_language) {
393
-
394
- $slug_translation = apply_filters('wpml_translate_single_string', $slug, $this->url_strings_context(), $this->url_string_name( 'attribute' ) );
395
- if ($slug_translation) {
396
-
397
- $slug_match = addslashes( ltrim($slug, '/') );
398
- $slug_translation_match = ltrim($slug_translation, '/');
399
-
400
- $buff_value = array();
401
- foreach ((array)$value as $k => $v) {
402
- if ($slug != $slug_translation && preg_match('#^' . $slug_match . '/(.*)#', $k)) {
403
- $k = preg_replace('#^' . $slug_match . '/(.*)#', $slug_translation_match . '/$1', $k);
404
- }
405
- $buff_value[$k] = $v;
406
- }
407
-
408
- $value = $buff_value;
409
- unset($buff_value);
410
-
411
- }
412
-
413
- }
414
- }
415
-
416
- }
417
-
418
-
419
-
420
- //filter shop page rewrite slug
421
- $current_shop_id = wc_get_page_id( 'shop' );
422
- $default_shop_id = apply_filters( 'translate_object_id', $current_shop_id, 'page', true, $sitepress->get_default_language() );
423
-
424
- if ( is_null( get_post( $current_shop_id ) ) || is_null( get_post( $default_shop_id ) ) )
425
- return $value;
426
-
427
- $current_slug = get_post( $current_shop_id )->post_name;
428
- $default_slug = get_post( $default_shop_id )->post_name;
429
-
430
- if ( $current_slug != $default_slug ) {
431
- $buff_value = array();
432
- foreach ( (array)$value as $k => $v ) {
433
-
434
- if( preg_match( '#^' . $default_slug . '/\?\$$#', $k ) ||
435
- preg_match( '#^' . $default_slug . '/\(?feed#', $k ) ||
436
- preg_match( '#^' . $default_slug . '/page#', $k )){
437
-
438
- $k = preg_replace( '#^' . $default_slug . '/#', $current_slug . '/', $k );
439
- }
440
-
441
- $buff_value[$k] = $v;
442
- }
443
-
444
- $value = $buff_value;
445
- unset( $buff_value );
446
- }
447
-
448
-
 
 
449
  return $value;
450
  }
451
 
452
  function translate_taxonomy_base( $termlink, $term, $taxonomy ) {
453
- global $wp_rewrite, $wpml_term_translations, $sitepress;
454
  static $no_recursion_flag;
455
 
456
  // handles product categories, product tags and attributes
@@ -473,7 +477,7 @@ class WCML_Url_Translation {
473
  if ( !is_null( $wpml_term_translations ) ) {
474
  $term_language = $term->term_id ? $wpml_term_translations->get_element_lang_code( $term->term_taxonomy_id ) : false;
475
  } else {
476
- $term_language = $term->term_id ? $sitepress->get_language_for_element( $term->term_taxonomy_id, 'tax_' . $taxonomy ) : false;
477
  }
478
 
479
  if ( $term_language ) {
@@ -507,27 +511,26 @@ class WCML_Url_Translation {
507
  }
508
 
509
  function get_translated_tax_slug( $taxonomy, $language = false ) {
510
- global $sitepress, $woocommerce_wpml;
511
 
512
  switch ( $taxonomy ) {
513
  case 'product_tag':
514
  $slug = !empty( $this->wc_permalinks['tag_base'] ) ? trim( $this->wc_permalinks['tag_base'], '/' ) : 'product-tag';
515
 
516
- $string_language = $woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $this->url_string_name( $taxonomy ) );
517
 
518
  break;
519
 
520
  case 'product_cat':
521
  $slug = !empty( $this->wc_permalinks['category_base'] ) ? trim( $this->wc_permalinks['category_base'], '/' ) : 'product-category';
522
 
523
- $string_language = $woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $this->url_string_name( $taxonomy ) );
524
 
525
  break;
526
 
527
  default:
528
  $slug = trim( $this->wc_permalinks['attribute_base'], '/' );
529
 
530
- $string_language = $woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $this->url_string_name( 'attribute' ) );
531
 
532
  $taxonomy = 'attribute';
533
 
@@ -535,7 +538,7 @@ class WCML_Url_Translation {
535
  }
536
 
537
  if ( !$language ) {
538
- $language = $sitepress->get_current_language();
539
  }
540
 
541
 
6
  public $default_product_category_base;
7
  public $default_product_tag_base;
8
 
9
+ private $woocommerce_wpml;
10
+ private $sitepress;
11
+
12
+ function __construct( &$woocommerce_wpml, &$sitepress ) {
13
+
14
+ $this->woocommerce_wpml =& $woocommerce_wpml;
15
+ $this->sitepress =& $sitepress;
16
 
17
  $this->default_product_base = 'product';
18
  $this->default_product_category_base = 'product-category';
35
  }
36
 
37
  function set_up() {
 
38
 
39
+ if ( empty( $this->woocommerce_wpml->settings['url_translation_set_up'] ) ) {
40
 
41
  $this->clean_up_product_and_taxonomy_bases();
42
 
45
 
46
  $this->register_product_and_taxonomy_bases();
47
 
48
+ $this->woocommerce_wpml->settings['url_translation_set_up'] = 1;
49
+ $this->woocommerce_wpml->update_settings();
50
  }
51
 
52
  }
145
  } else {
146
 
147
  // force_product_slug_translation_on
148
+ $iclsettings = $this->sitepress->get_settings();
 
149
  if ( empty( $iclsettings['posts_slug_translation']['on'] ) || empty( $iclsettings['posts_slug_translation']['types']['product'] ) ) {
150
  $iclsettings['posts_slug_translation']['on'] = 1;
151
  $iclsettings['posts_slug_translation']['types']['product'] = 1;
152
+ $this->sitepress->save_settings( $iclsettings );
153
  }
154
 
155
  $string = icl_get_string_id( $slug, $this->url_strings_context(), $this->url_string_name( 'product' ) );
174
  }
175
 
176
  function register_product_and_taxonomy_bases( $value = false, $old_value = false ) {
 
177
 
178
  if( empty( $value ) ){
179
  $permalink_options = $this->wc_permalinks;
185
  $product_base = !empty( $permalink_options['product_base'] ) ? trim( $permalink_options['product_base'], '/' ) : $this->default_product_base;
186
  $name = $this->url_string_name( 'product' );
187
 
188
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $product_base, $this->url_strings_context(), $name );
189
  if( is_null($string_language) ){
190
  $string_language = '';
191
  }
192
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $name, $product_base, false, $string_language );
193
 
194
  if( isset($_POST['product_base_language'])){
195
+ $this->woocommerce_wpml->strings->set_string_language( $product_base, $this->url_strings_context(), $name, $_POST['product_base_language']);
196
  }
197
 
198
  if ( $product_base == $this->default_product_base ) {
203
  $category_base = !empty( $permalink_options['category_base'] ) ? $permalink_options['category_base'] : $this->default_product_category_base;
204
  $name = $this->url_string_name( 'product_cat' );
205
 
206
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $category_base, $this->url_strings_context(), $name );
207
  if( is_null($string_language) ){
208
  $string_language = '';
209
  }
210
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $name, $category_base, false, $string_language );
211
 
212
  if( isset($_POST['category_base_language'])){
213
+ $this->woocommerce_wpml->strings->set_string_language( $category_base, $this->url_strings_context(), $name, $_POST['category_base_language']);
214
  }
215
 
216
  if ( $category_base == $this->default_product_category_base ) {
221
  $tag_base = !empty( $permalink_options['tag_base'] ) ? $permalink_options['tag_base'] : $this->default_product_tag_base;
222
  $name = $this->url_string_name( 'product_tag' );
223
 
224
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $tag_base, $this->url_strings_context(), $name );
225
  if( is_null($string_language) ){
226
  $string_language = '';
227
  }
228
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $name, $tag_base, false, $string_language );
229
 
230
  if( isset($_POST['tag_base_language'])){
231
+ $this->woocommerce_wpml->strings->set_string_language( $tag_base, $this->url_strings_context(), $name, $_POST['tag_base_language']);
232
  }
233
 
234
  if ( $tag_base == $this->default_product_tag_base ) {
239
  if ( isset( $permalink_options['attribute_base'] ) && $permalink_options['attribute_base'] ) {
240
  $attr_base = trim( $permalink_options['attribute_base'], '/' );
241
 
242
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $attr_base, $this->url_strings_context(), $name );
243
  if( is_null($string_language) ){
244
  $string_language = '';
245
  }
246
  do_action( 'wpml_register_single_string', $this->url_strings_context(), $this->url_string_name( 'attribute' ), $attr_base, false, $string_language );
247
 
248
  if( isset($_POST['attribute_base_language'])){
249
+ $this->woocommerce_wpml->strings->set_string_language( $attr_base, $this->url_strings_context(), $this->url_string_name( 'attribute' ), $_POST['attribute_base_language']);
250
  }
251
  }
252
 
254
  }
255
 
256
  function add_default_slug_translations( $slug, $name ) {
257
+ global $wpdb;
258
 
259
  $string_id = icl_get_string_id( $slug, $this->url_strings_context(), $name );
260
 
261
  if ( WPML_SUPPORT_STRINGS_IN_DIFF_LANG ) {
262
 
263
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $name );
264
 
265
  // will use a filter in the future wpmlst-529
266
  $string_object = new WPML_ST_String( $string_id, $wpdb );
276
  $string_translations[$s->language] = $s->status;
277
  }
278
 
279
+ $languages = $this->sitepress->get_active_languages();
280
 
281
  foreach ( $languages as $language => $language_info ) {
282
 
285
  // check if there's an existing translation
286
  if ( !isset( $string_translations[$language] ) ) {
287
 
288
+ $slug_translation = $this->woocommerce_wpml->strings->get_translation_from_woocommerce_mo_file( $slug, $language, false );
289
 
290
  if ( $slug_translation ) {
291
  // add string translation
300
  }
301
 
302
  function force_bases_in_strings_languages( $value ) {
 
303
 
304
+ if( $value && $this->sitepress->get_current_language() != 'en' ) {
305
 
306
+ remove_filter( 'gettext_with_context', array( $this->woocommerce_wpml->strings, 'category_base_in_strings_language' ), 99, 3 );
307
  $taxonomies = array(
308
  'product_cat' => array(
309
  'base' => 'category_base',
316
  'default' => $this->default_product_tag_base
317
  ),
318
  );
319
+ add_filter( 'gettext_with_context', array( $this->woocommerce_wpml->strings, 'category_base_in_strings_language' ), 99, 3 );
320
 
321
  foreach ( $taxonomies as $taxonomy => $taxonomy_details ) {
322
 
341
  }
342
 
343
  function translate_bases_in_rewrite_rules( $value ) {
344
+ global $sitepress_settings;
345
+
346
+ if ( ! empty( $value ) ) {
347
+
348
+ $taxonomies = array( 'product_cat', 'product_tag' );
349
+
350
+ foreach ( $taxonomies as $taxonomy ) {
351
+ $slug_details = $this->get_translated_tax_slug( $taxonomy );
352
+
353
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $slug_details['slug'], $this->url_strings_context(), $this->url_string_name( $taxonomy ) );
354
+ if ( $this->sitepress->get_current_language() == $string_language ) {
355
+ continue;
356
+ }
357
+
358
+ if ( $slug_details ) {
359
+
360
+ $slug_match = addslashes( ltrim($slug_details['slug'], '/') );
361
+ $slug_translation_match = ltrim($slug_details['translated_slug'], '/');
362
+
363
+ $buff_value = array();
364
+ foreach ( (array)$value as $k => $v ) {
365
+
366
+ if ( $slug_details['slug'] != $slug_details['translated_slug'] && preg_match( '#^[^/]*/?' . $slug_match . '/#', $k ) ) {
367
+ $k = preg_replace( '#^([^/]*)(/?)' . $slug_match . '/#', '$1$2' . $slug_translation_match . '/', $k );
368
+ }
369
+
370
+ $buff_value[$k] = $v;
371
+ }
372
+ $value = $buff_value;
373
+ unset( $buff_value );
374
+ }
375
+
376
+ }
377
+
378
+ // handle attributes
379
+ $wc_taxonomies = wc_get_attribute_taxonomies();
380
+ $wc_taxonomies_wc_format = array();
381
+ foreach ( $wc_taxonomies as $k => $v ) {
382
+ $wc_taxonomies_wc_format[] = 'pa_' . $v->attribute_name;
383
+ }
384
+
385
+ foreach ( $wc_taxonomies_wc_format as $taxonomy ) {
386
+ $taxonomy_obj = get_taxonomy( $taxonomy );
387
+
388
+ if ( isset( $taxonomy_obj->rewrite['slug'] ) ) {
389
+ $exp = explode( '/', trim( $taxonomy_obj->rewrite['slug'], '/' ) );
390
+ $slug = join( '/', array_slice( $exp, 0, count( $exp ) - 1 ) );
391
+ }
392
+
393
+ if ( isset( $slug ) ) {
394
+ $string_language = $this->woocommerce_wpml->strings->get_string_language($slug, $this->url_strings_context(), $this->url_string_name( 'attribute' ) );
395
+
396
+ if ($this->sitepress->get_current_language() != $string_language) {
397
+
398
+ $slug_translation = apply_filters('wpml_translate_single_string', $slug, $this->url_strings_context(), $this->url_string_name( 'attribute' ) );
399
+ if ($slug_translation) {
400
+
401
+ $slug_match = addslashes( ltrim($slug, '/') );
402
+ $slug_translation_match = ltrim($slug_translation, '/');
403
+
404
+ $buff_value = array();
405
+ foreach ((array)$value as $k => $v) {
406
+ if ($slug != $slug_translation && preg_match('#^' . $slug_match . '/(.*)#', $k)) {
407
+ $k = preg_replace('#^' . $slug_match . '/(.*)#', $slug_translation_match . '/$1', $k);
408
+ }
409
+ $buff_value[$k] = $v;
410
+ }
411
+
412
+ $value = $buff_value;
413
+ unset($buff_value);
414
+
415
+ }
416
+
417
+ }
418
+ }
419
+
420
+ }
421
+
422
+
423
+
424
+ //filter shop page rewrite slug
425
+ $current_shop_id = wc_get_page_id( 'shop' );
426
+ $default_shop_id = apply_filters( 'translate_object_id', $current_shop_id, 'page', true, $this->sitepress->get_default_language() );
427
+
428
+ if ( is_null( get_post( $current_shop_id ) ) || is_null( get_post( $default_shop_id ) ) )
429
+ return $value;
430
+
431
+ $current_slug = get_post( $current_shop_id )->post_name;
432
+ $default_slug = get_post( $default_shop_id )->post_name;
433
+
434
+ if ( $current_slug != $default_slug ) {
435
+ $buff_value = array();
436
+ foreach ( (array)$value as $k => $v ) {
437
+
438
+ if( preg_match( '#^' . $default_slug . '/\?\$$#', $k ) ||
439
+ preg_match( '#^' . $default_slug . '/\(?feed#', $k ) ||
440
+ preg_match( '#^' . $default_slug . '/page#', $k )){
441
+
442
+ $k = preg_replace( '#^' . $default_slug . '/#', $current_slug . '/', $k );
443
+ }
444
+
445
+ $buff_value[$k] = $v;
446
+ }
447
+
448
+ $value = $buff_value;
449
+ unset( $buff_value );
450
+ }
451
+ }
452
+
453
  return $value;
454
  }
455
 
456
  function translate_taxonomy_base( $termlink, $term, $taxonomy ) {
457
+ global $wp_rewrite, $wpml_term_translations;
458
  static $no_recursion_flag;
459
 
460
  // handles product categories, product tags and attributes
477
  if ( !is_null( $wpml_term_translations ) ) {
478
  $term_language = $term->term_id ? $wpml_term_translations->get_element_lang_code( $term->term_taxonomy_id ) : false;
479
  } else {
480
+ $term_language = $term->term_id ? $this->sitepress->get_language_for_element( $term->term_taxonomy_id, 'tax_' . $taxonomy ) : false;
481
  }
482
 
483
  if ( $term_language ) {
511
  }
512
 
513
  function get_translated_tax_slug( $taxonomy, $language = false ) {
 
514
 
515
  switch ( $taxonomy ) {
516
  case 'product_tag':
517
  $slug = !empty( $this->wc_permalinks['tag_base'] ) ? trim( $this->wc_permalinks['tag_base'], '/' ) : 'product-tag';
518
 
519
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $this->url_string_name( $taxonomy ) );
520
 
521
  break;
522
 
523
  case 'product_cat':
524
  $slug = !empty( $this->wc_permalinks['category_base'] ) ? trim( $this->wc_permalinks['category_base'], '/' ) : 'product-category';
525
 
526
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $this->url_string_name( $taxonomy ) );
527
 
528
  break;
529
 
530
  default:
531
  $slug = trim( $this->wc_permalinks['attribute_base'], '/' );
532
 
533
+ $string_language = $this->woocommerce_wpml->strings->get_string_language( $slug, $this->url_strings_context(), $this->url_string_name( 'attribute' ) );
534
 
535
  $taxonomy = 'attribute';
536
 
538
  }
539
 
540
  if ( !$language ) {
541
+ $language = $this->sitepress->get_current_language();
542
  }
543
 
544
 
readme.txt CHANGED
@@ -4,8 +4,8 @@ Donate link: http://wpml.org/documentation/related-projects/woocommerce-multilin
4
  Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multilingual, e-shop, shop
5
  License: GPLv2
6
  Requires at least: 3.0
7
- Tested up to: 4.4.2
8
- Stable tag: 3.7.11
9
 
10
  Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
@@ -78,6 +78,11 @@ In order for the checkout and store pages to appear translated, you need to crea
78
 
79
  == Changelog ==
80
 
 
 
 
 
 
81
  = 3.7.11 =
82
  * Bug fix: the downloadable products were not synced properly with their translations
83
  * Bug fix: the confirmation for installing WooCommerce translations for the secondary languages was not saved
4
  Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multilingual, e-shop, shop
5
  License: GPLv2
6
  Requires at least: 3.0
7
+ Tested up to: 4.5
8
+ Stable tag: 3.7.12
9
 
10
  Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
78
 
79
  == Changelog ==
80
 
81
+ = 3.7.12 =
82
+ * Fixed a bug that made the shop pages return 404 errors on WordPress 4.5
83
+ * Fixed warnings caused by terms translated before the WooCommerce Multilingual activation
84
+ * Bug fix: WooCommerce Multilingual locales for secondary languages were not loaded correctly
85
+
86
  = 3.7.11 =
87
  * Bug fix: the downloadable products were not synced properly with their translations
88
  * Bug fix: the confirmation for installing WooCommerce translations for the secondary languages was not saved
woocommerce_wpml.class.php CHANGED
@@ -60,7 +60,7 @@ class woocommerce_wpml {
60
  $this->xdomain_data = new xDomain_Data;
61
  $this->languages_upgrader = new WCML_Languages_Upgrader;
62
 
63
- $this->url_translation = new WCML_Url_Translation;
64
 
65
 
66
 
@@ -177,7 +177,22 @@ class woocommerce_wpml {
177
  }
178
 
179
  function load_locale(){
180
- load_plugin_textdomain('woocommerce-multilingual', false, WCML_LOCALE_PATH);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
181
  }
182
 
183
  function install(){
@@ -214,6 +229,7 @@ class woocommerce_wpml {
214
  self::set_up_capabilities();
215
 
216
  $this->set_language_information();
 
217
 
218
  $this->settings['set_up'] = 1;
219
  $this->update_settings();
@@ -265,8 +281,8 @@ class woocommerce_wpml {
265
  foreach($products as $product){
266
  $exist = $sitepress->get_language_for_element($product->ID,'post_product');
267
  if(!$exist){
268
- $sitepress->set_element_language_details($product->ID, 'post_product',false,$def_lang);
269
- }
270
  }
271
 
272
  //set language info for taxonomies
@@ -274,24 +290,84 @@ class woocommerce_wpml {
274
  foreach($terms as $term){
275
  $exist = $sitepress->get_language_for_element($term->term_taxonomy_id, 'tax_product_cat');
276
  if(!$exist){
277
- $sitepress->set_element_language_details($term->term_taxonomy_id, 'tax_product_cat',false,$def_lang);
278
- }
279
  }
280
  $terms = $wpdb->get_results("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'product_tag'");
281
  foreach($terms as $term){
282
  $exist = $sitepress->get_language_for_element($term->term_taxonomy_id, 'tax_product_tag');
283
  if(!$exist){
284
- $sitepress->set_element_language_details($term->term_taxonomy_id, 'tax_product_tag',false,$def_lang);
285
- }
286
  }
287
 
288
  $terms = $wpdb->get_results("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'product_shipping_class'");
289
  foreach($terms as $term){
290
  $exist = $sitepress->get_language_for_element($term->term_taxonomy_id, 'tax_product_shipping_class');
291
  if(!$exist){
292
- $sitepress->set_element_language_details($term->term_taxonomy_id, 'tax_product_shipping_class',false,$def_lang);
 
293
  }
294
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
295
  }
296
 
297
  function menu(){
60
  $this->xdomain_data = new xDomain_Data;
61
  $this->languages_upgrader = new WCML_Languages_Upgrader;
62
 
63
+ $this->url_translation = new WCML_Url_Translation( $this, $sitepress );
64
 
65
 
66
 
177
  }
178
 
179
  function load_locale(){
180
+ return load_plugin_textdomain('woocommerce-multilingual', false, WCML_PLUGIN_FOLDER.'/locale' );
181
+ }
182
+
183
+ public function switch_locale( $lang_code = false ){
184
+ global $l10n, $sitepress;
185
+ static $original_l10n;
186
+ if (!empty($lang_code)) {
187
+ $original_l10n = isset($l10n['woocommerce-multilingual']) ? $l10n['woocommerce-multilingual'] : null;
188
+ if ($original_l10n !== null) {
189
+ unset($l10n['woocommerce-multilingual']);
190
+ }
191
+ return load_textdomain('woocommerce-multilingual',
192
+ WCML_LOCALE_PATH . '/woocommerce-multilingual-' . $sitepress->get_locale($lang_code) . '.mo');
193
+ } else { // switch back
194
+ $l10n['woocommerce-multilingual'] = $original_l10n;
195
+ }
196
  }
197
 
198
  function install(){
229
  self::set_up_capabilities();
230
 
231
  $this->set_language_information();
232
+ $this->check_product_type_terms();
233
 
234
  $this->settings['set_up'] = 1;
235
  $this->update_settings();
281
  foreach($products as $product){
282
  $exist = $sitepress->get_language_for_element($product->ID,'post_product');
283
  if(!$exist){
284
+ $sitepress->set_element_language_details($product->ID, 'post_product',false,$def_lang);
285
+ }
286
  }
287
 
288
  //set language info for taxonomies
290
  foreach($terms as $term){
291
  $exist = $sitepress->get_language_for_element($term->term_taxonomy_id, 'tax_product_cat');
292
  if(!$exist){
293
+ $sitepress->set_element_language_details($term->term_taxonomy_id, 'tax_product_cat',false,$def_lang);
294
+ }
295
  }
296
  $terms = $wpdb->get_results("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'product_tag'");
297
  foreach($terms as $term){
298
  $exist = $sitepress->get_language_for_element($term->term_taxonomy_id, 'tax_product_tag');
299
  if(!$exist){
300
+ $sitepress->set_element_language_details($term->term_taxonomy_id, 'tax_product_tag',false,$def_lang);
301
+ }
302
  }
303
 
304
  $terms = $wpdb->get_results("SELECT term_taxonomy_id FROM $wpdb->term_taxonomy WHERE taxonomy = 'product_shipping_class'");
305
  foreach($terms as $term){
306
  $exist = $sitepress->get_language_for_element($term->term_taxonomy_id, 'tax_product_shipping_class');
307
  if(!$exist){
308
+ $sitepress->set_element_language_details($term->term_taxonomy_id, 'tax_product_shipping_class',false,$def_lang);
309
+ }
310
  }
311
  }
312
+
313
+ //handle situation when product_type terms translated before activating WCML
314
+ function check_product_type_terms(){
315
+ global $wpdb;
316
+ //check if terms were translated
317
+ $translations = $wpdb->get_results( "SELECT * FROM {$wpdb->prefix}icl_translations WHERE element_type = 'tax_product_type'" );
318
+
319
+ if( $translations ){
320
+ foreach( $translations as $translation ){
321
+ if( !is_null( $translation->source_language_code ) ){
322
+ //check relationships
323
+ $term_relationships = $wpdb->get_results( $wpdb->prepare( "SELECT * FROM {$wpdb->term_relationships} WHERE term_taxonomy_id = %d", $translation->element_id ) );
324
+ if( $term_relationships ){
325
+ $orig_term = $wpdb->get_var( $wpdb->prepare( "SELECT element_id FROM {$wpdb->prefix}icl_translations WHERE element_type = 'tax_product_type' AND trid = %d AND source_language_code IS NULL", $translation->trid ) );
326
+ if( $orig_term ){
327
+ foreach( $term_relationships as $term_relationship ){
328
+ $wpdb->update(
329
+ $wpdb->term_relationships,
330
+ array(
331
+ 'term_taxonomy_id' => $orig_term
332
+ ),
333
+ array(
334
+ 'object_id' => $term_relationship->object_id,
335
+ 'term_taxonomy_id' => $translation->element_id
336
+ )
337
+ );
338
+ }
339
+ }
340
+ }
341
+
342
+ $term_id = $wpdb->get_var( $wpdb->prepare( "SELECT term_id FROM {$wpdb->term_taxonomy} WHERE term_taxonomy_id = %d", $translation->element_id ) );
343
+
344
+ if( $term_id ){
345
+ $wpdb->delete(
346
+ $wpdb->terms,
347
+ array(
348
+ 'term_id' => $term_id
349
+ )
350
+ );
351
+
352
+ $wpdb->delete(
353
+ $wpdb->term_taxonomy,
354
+ array(
355
+ 'term_taxonomy_id' => $translation->element_id
356
+ )
357
+ );
358
+ }
359
+ }
360
+ }
361
+
362
+ foreach( $translations as $translation ){
363
+ $wpdb->delete(
364
+ $wpdb->prefix . 'icl_translations',
365
+ array(
366
+ 'translation_id' => $translation->translation_id
367
+ )
368
+ );
369
+ }
370
+ }
371
  }
372
 
373
  function menu(){
wpml-woocommerce.php CHANGED
@@ -6,16 +6,16 @@
6
  Author: OnTheGoSystems
7
  Author URI: http://www.onthegosystems.com/
8
  Text Domain: woocommerce-multilingual
9
- Version: 3.7.11
10
  */
11
 
12
 
13
  if(defined('WCML_VERSION')) return;
14
- define('WCML_VERSION', '3.7.11');
15
  define('WCML_PLUGIN_PATH', dirname(__FILE__));
16
  define('WCML_PLUGIN_FOLDER', basename(WCML_PLUGIN_PATH));
17
- define('WCML_LOCALE_PATH',WCML_PLUGIN_PATH.'/locale');
18
- define('WPML_LOAD_API_SUPPORT',true);
19
 
20
  define('WCML_MULTI_CURRENCIES_DISABLED', 0);
21
  define('WCML_MULTI_CURRENCIES_PER_LANGUAGE', 1); //obsolete - migrate to 2
6
  Author: OnTheGoSystems
7
  Author URI: http://www.onthegosystems.com/
8
  Text Domain: woocommerce-multilingual
9
+ Version: 3.7.12
10
  */
11
 
12
 
13
  if(defined('WCML_VERSION')) return;
14
+ define('WCML_VERSION', '3.7.12');
15
  define('WCML_PLUGIN_PATH', dirname(__FILE__));
16
  define('WCML_PLUGIN_FOLDER', basename(WCML_PLUGIN_PATH));
17
+ define('WCML_LOCALE_PATH', WCML_PLUGIN_PATH.'/locale');
18
+ define('WPML_LOAD_API_SUPPORT', true);
19
 
20
  define('WCML_MULTI_CURRENCIES_DISABLED', 0);
21
  define('WCML_MULTI_CURRENCIES_PER_LANGUAGE', 1); //obsolete - migrate to 2