WooCommerce Multilingual – run WooCommerce with WPML - Version 1.0

Version Description

  • Fixed 'Return to store' URL
  • Fixed language selector for the translated shop base pages
  • Fixed the product remove URL in the translated language
  • Fixed the checkout URL in the translated language
  • Fix to prevent incorrect product URL in the shop base page when the permalink is not 'shop'
Download this release

Release Info

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

Code changes from version 0.9 to 1.0

Files changed (2) hide show
  1. readme.txt +20 -10
  2. wpml-woocommerce.php +61 -18
readme.txt CHANGED
@@ -1,16 +1,17 @@
1
  === WooCommerce Multilingual - run WooCommerce with WPML ===
2
- Contributors: dominykasgel, AmirHelzer
3
  Donate link: http://wp-types.com
4
- Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multilingual
5
- Requires at least: 3.2.1
6
  Tested up to: 3.3.1
7
- Stable tag: 0.9
 
8
 
9
- Allows running multilingual e-commerce sites using WooCommerce and WPML.
10
 
11
  == Description ==
12
 
13
- This 'glue' plugin makes it possible to run fully multilignual e-commerce sites using WooCommerce and WPML. It makes products and store pages translatable, lets visitors switch languages and order products in their language.
14
 
15
  = Features =
16
 
@@ -31,9 +32,9 @@ You will need:
31
 
32
  == Installation ==
33
 
34
- 1. Upload 'types' to the '/wp-content/plugins/' directory
35
  2. Activate the plugin through the 'Plugins' menu in WordPress
36
-
37
 
38
  == Frequently Asked Questions ==
39
 
@@ -47,11 +48,20 @@ No. This plugin is tailored for WooCommerce.
47
 
48
  == Changelog ==
49
 
 
 
 
 
 
 
 
50
  = 0.9 =
51
  * First release
52
 
53
  == Upgrade Notice ==
54
 
55
- = 0.9 =
56
- * First release
57
 
 
 
1
  === WooCommerce Multilingual - run WooCommerce with WPML ===
2
+ Contributors: AmirHelzer, dominykasgel
3
  Donate link: http://wp-types.com
4
+ Tags: CMS, woocommerce, commerce, ecommerce, e-commerce, products, WPML, multilingual, e-shop, shop
5
+ Requires at least: 3.0
6
  Tested up to: 3.3.1
7
+ Stable tag: 1.0
8
+ Version: 1.0
9
 
10
+ Allows running fully multilingual e-commerce sites using WooCommerce and WPML.
11
 
12
  == Description ==
13
 
14
+ This 'glue' plugin makes it possible to run fully multilingual e-commerce sites using WooCommerce and WPML. It makes products and store pages translatable, lets visitors switch languages and order products in their language.
15
 
16
  = Features =
17
 
32
 
33
  == Installation ==
34
 
35
+ 1. Upload 'woocommerce-multilingual' to the '/wp-content/plugins/' directory
36
  2. Activate the plugin through the 'Plugins' menu in WordPress
37
+ 3. Translate the shop pages
38
 
39
  == Frequently Asked Questions ==
40
 
48
 
49
  == Changelog ==
50
 
51
+ = 1.0 =
52
+ * Fixed 'Return to store' URL
53
+ * Fixed language selector for the translated shop base pages
54
+ * Fixed the product remove URL in the translated language
55
+ * Fixed the checkout URL in the translated language
56
+ * Fix to prevent incorrect product URL in the shop base page when the permalink is not 'shop'
57
+
58
  = 0.9 =
59
  * First release
60
 
61
  == Upgrade Notice ==
62
 
63
+ = 1.0 =
64
+ Recommended update! Fixed a few bugs;
65
 
66
+ = 0.9 =
67
+ * First release
wpml-woocommerce.php CHANGED
@@ -5,7 +5,7 @@
5
  Description: Allows running fully multilingual e-Commerce sites with WooCommerce and WPML. <a href="http://wpml.org/documentation/related-projects/woocommerce-multilingual/">Documentation</a>.
6
  Author: ICanLocalize
7
  Author URI: http://wpml.org/
8
- Version: 0.9
9
  */
10
  add_action('plugins_loaded', 'wpml_woocommerce_init', 2);
11
 
@@ -22,6 +22,9 @@ function wpml_woocommerce_init(){
22
  add_action('admin_notices', 'wpml_no_woocommerce');
23
  return false;
24
  }
 
 
 
25
 
26
  add_filter('woocommerce_get_checkout_url', 'wpml_get_checkout_url');
27
  add_filter('woocommerce_get_cart_page_id', 'wpml_get_cart_url');
@@ -40,12 +43,13 @@ function wpml_woocommerce_init(){
40
  add_filter('woocommerce_in_cart_product_id', 'wpml_in_cart_product_id', 11, 2);
41
  add_filter('woocommerce_params', 'wpml_params');
42
  add_filter('woocommerce_redirect', 'wpml_redirect');
43
- add_filter('wp_head', 'wpml_redirect_to_store');
44
 
45
  add_action("updated_post_meta", 'wpml_updated_post_meta_hook', 10, 4);
46
  add_action('woocommerce_email_header', 'wpml_email_header', 0);
47
  add_action('woocommerce_email_footer', 'wpml_email_footer', 0);
48
  add_action('woocommerce_new_order', 'wpml_order_language');
 
49
  }
50
 
51
  /**
@@ -133,19 +137,19 @@ function wpml_updated_post_meta_hook($meta_id, $object_id, $meta_key, $_meta_val
133
  * @global type $post
134
  * @global type $sitepress
135
  */
136
- function wpml_redirect_to_store(){
137
  global $post, $sitepress;
138
 
139
  $shop_page_id = get_option('woocommerce_shop_page_id');
140
  $translated_shop_page_id = icl_object_id($shop_page_id, 'page', false);
141
 
142
- if(is_page($translated_shop_page_id)){
143
  wp_safe_redirect($sitepress->convert_url(get_option('home') . '/?post_type=product'));
144
  }
145
  }
146
 
147
  /**
148
- * Filters WooCommerce cancel order (payment gateway).
149
  *
150
  * @global type $sitepress
151
  * @param type $link
@@ -157,7 +161,7 @@ function wpml_get_cancel_order_url($link){
157
  }
158
 
159
  /**
160
- * Filters WooCommerce return URL after payment (payment gateway e.g. PayPal).
161
  *
162
  * @global type $sitepress
163
  * @param type $link
@@ -183,20 +187,13 @@ function wpml_redirect($link){
183
  /**
184
  * Filters WooCommerce shop link.
185
  *
186
- * @global type $sitepress
187
  * @param type $link
188
  * @return type
189
  */
190
  function wpml_shop_page_id($link){
191
- global $sitepress;
192
 
193
- if($sitepress->get_current_language() !== $sitepress->get_default_language()){
194
- $shop_page_id = icl_object_id(get_option('woocommerce_shop_page_id'), 'page', true);
195
- } else {
196
- $shop_page_id = $sitepress->convert_url(get_option('home') . '/?post_type=product');
197
- }
198
-
199
- return $shop_page_id;
200
  }
201
 
202
  /**
@@ -254,7 +251,7 @@ function wpml_pay_page_id(){
254
  $is_cart_page = icl_object_id(get_option('woocommerce_cart_page_id'), 'page', true);
255
 
256
  if(is_page($is_cart_page)){
257
- return true;
258
  } else {
259
  return icl_object_id(get_option('woocommerce_pay_page_id'), 'page', true);
260
  }
@@ -269,7 +266,8 @@ function wpml_pay_page_id(){
269
  */
270
  function wpml_get_checkout_url($link){
271
  global $sitepress;
272
- return $sitepress->convert_url($link);
 
273
  }
274
 
275
  /**
@@ -290,7 +288,8 @@ function wpml_get_cart_url($link) {
290
  */
291
  function wpml_get_remove_url($link){
292
  global $sitepress;
293
- return $sitepress->convert_url($link);
 
294
  }
295
 
296
  /**
@@ -393,4 +392,48 @@ function wpml_in_cart_product_title($title, $_product){
393
  return $title;
394
  }
395
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
396
  ?>
5
  Description: Allows running fully multilingual e-Commerce sites with WooCommerce and WPML. <a href="http://wpml.org/documentation/related-projects/woocommerce-multilingual/">Documentation</a>.
6
  Author: ICanLocalize
7
  Author URI: http://wpml.org/
8
+ Version: 1.0
9
  */
10
  add_action('plugins_loaded', 'wpml_woocommerce_init', 2);
11
 
22
  add_action('admin_notices', 'wpml_no_woocommerce');
23
  return false;
24
  }
25
+
26
+ // Filter WPML language switcher
27
+ add_filter('icl_ls_languages', 'wpml_ls_filter');
28
 
29
  add_filter('woocommerce_get_checkout_url', 'wpml_get_checkout_url');
30
  add_filter('woocommerce_get_cart_page_id', 'wpml_get_cart_url');
43
  add_filter('woocommerce_in_cart_product_id', 'wpml_in_cart_product_id', 11, 2);
44
  add_filter('woocommerce_params', 'wpml_params');
45
  add_filter('woocommerce_redirect', 'wpml_redirect');
46
+ add_filter('wp_head', 'wpml_redirect_to_shop_base_page');
47
 
48
  add_action("updated_post_meta", 'wpml_updated_post_meta_hook', 10, 4);
49
  add_action('woocommerce_email_header', 'wpml_email_header', 0);
50
  add_action('woocommerce_email_footer', 'wpml_email_footer', 0);
51
  add_action('woocommerce_new_order', 'wpml_order_language');
52
+ add_action('init', 'wpml_change_permalinks');
53
  }
54
 
55
  /**
137
  * @global type $post
138
  * @global type $sitepress
139
  */
140
+ function wpml_redirect_to_shop_base_page(){
141
  global $post, $sitepress;
142
 
143
  $shop_page_id = get_option('woocommerce_shop_page_id');
144
  $translated_shop_page_id = icl_object_id($shop_page_id, 'page', false);
145
 
146
+ if(is_page(array($translated_shop_page_id, $shop_page_id))){
147
  wp_safe_redirect($sitepress->convert_url(get_option('home') . '/?post_type=product'));
148
  }
149
  }
150
 
151
  /**
152
+ * Filters WooCommerce cancel order.
153
  *
154
  * @global type $sitepress
155
  * @param type $link
161
  }
162
 
163
  /**
164
+ * Filters WooCommerce return URL after payment.
165
  *
166
  * @global type $sitepress
167
  * @param type $link
187
  /**
188
  * Filters WooCommerce shop link.
189
  *
 
190
  * @param type $link
191
  * @return type
192
  */
193
  function wpml_shop_page_id($link){
194
+ $link = icl_object_id(get_option('woocommerce_shop_page_id'), 'page', false);
195
 
196
+ return $link;
 
 
 
 
 
 
197
  }
198
 
199
  /**
251
  $is_cart_page = icl_object_id(get_option('woocommerce_cart_page_id'), 'page', true);
252
 
253
  if(is_page($is_cart_page)){
254
+ //return true;
255
  } else {
256
  return icl_object_id(get_option('woocommerce_pay_page_id'), 'page', true);
257
  }
266
  */
267
  function wpml_get_checkout_url($link){
268
  global $sitepress;
269
+
270
+ return get_permalink(icl_object_id(get_option('woocommerce_checkout_page_id'), 'page', true));
271
  }
272
 
273
  /**
288
  */
289
  function wpml_get_remove_url($link){
290
  global $sitepress;
291
+
292
+ return $link;
293
  }
294
 
295
  /**
392
  return $title;
393
  }
394
 
395
+ /**
396
+ * Filters WPML language switcher.
397
+ *
398
+ * @global type $post
399
+ * @global type $sitepress
400
+ * @param type $languages
401
+ * @return type
402
+ */
403
+ function wpml_ls_filter($languages) {
404
+ global $post, $sitepress;
405
+
406
+ $translated_checkout_page_id = icl_object_id(get_option('woocommerce_checkout_page_id'), 'page', false);
407
+ $shop_page_id = get_option('woocommerce_shop_page_id');
408
+
409
+ if(strpos(basename($_SERVER['REQUEST_URI']), 'post_type') !== false ||
410
+ strpos(basename($_SERVER['REQUEST_URI']), 'shop') !== false){
411
+
412
+ foreach($languages as $lang_code => $language){
413
+ $languages[$lang_code]['url'] = $sitepress->convert_url(get_option('home')
414
+ . '/?post_type=product', $language['language_code']);
415
+ }
416
+ }
417
+
418
+ return $languages;
419
+ }
420
+
421
+ /**
422
+ * Updates the shop base page permalink in the translated language.
423
+ * Needed for the correct products URLs in the shop base page.
424
+ *
425
+ * @global type $wpdb
426
+ * @return type
427
+ */
428
+ function wpml_change_permalinks(){
429
+ global $wpdb;
430
+
431
+ $translated_shop_page_id = icl_object_id(get_option('woocommerce_shop_page_id'), 'page', false);
432
+ $posts_query = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE `ID` = '$translated_shop_page_id'", ARRAY_A);
433
+
434
+ if($posts_query['post_name'] !== 'shop'){
435
+ $wpdb->update($wpdb->posts, array('post_name' => 'shop'), array('post_name' => $posts_query['post_name']));
436
+ }
437
+ }
438
+
439
  ?>