17
17
*
18
18
* @author Hyyan Abo Fakher <[email protected] >
19
19
*/
20
- class Pages
21
- {
20
+ class Pages {
21
+
22
22
/**
23
23
* Construct object.
24
24
*/
25
- public function __construct ()
26
- {
25
+ public function __construct () {
27
26
$ method = array ($ this , 'getPostTranslationID ' );
28
27
$ pages = apply_filters (HooksInterface::PAGES_LIST , array (
29
28
'shop ' ,
@@ -48,10 +47,9 @@ public function __construct()
48
47
/* To get product from current language in the shop page */
49
48
add_filter ('parse_request ' , array ($ this , 'correctShopPage ' ));
50
49
}
51
-
50
+
52
51
add_filter (
53
- 'woocommerce_shortcode_products_query ' ,
54
- array ($ this , 'addShortcodeLanguageFilter ' ), 10 , 2
52
+ 'woocommerce_shortcode_products_query ' , array ($ this , 'addShortcodeLanguageFilter ' ), 10 , 2
55
53
);
56
54
}
57
55
@@ -62,8 +60,7 @@ public function __construct()
62
60
*
63
61
* @return int
64
62
*/
65
- public function getPostTranslationID ($ id )
66
- {
63
+ public function getPostTranslationID ($ id ) {
67
64
if (!function_exists ('pll_get_post ' )) {
68
65
return $ id ;
69
66
}
@@ -85,8 +82,7 @@ public function getPostTranslationID($id)
85
82
* @return bool false if the current language is the same as default
86
83
* language or if the "pagename" var is empty
87
84
*/
88
- public function correctShopPage (\WP $ wp )
89
- {
85
+ public function correctShopPage (\WP $ wp ) {
90
86
global $ polylang ;
91
87
92
88
$ shopID = wc_get_page_id ('shop ' );
@@ -131,8 +127,7 @@ public function correctShopPage(\WP $wp)
131
127
*
132
128
* @return string translated url
133
129
*/
134
- public function translateShopUrl ($ url , $ language )
135
- {
130
+ public function translateShopUrl ($ url , $ language ) {
136
131
$ result = $ url ;
137
132
138
133
if (!is_post_type_archive ('product ' )) {
@@ -155,7 +150,7 @@ public function translateShopUrl($url, $language)
155
150
156
151
return $ result ;
157
152
}
158
-
153
+
159
154
/**
160
155
* Add Shortcode Language Filter
161
156
*
@@ -167,13 +162,18 @@ public function translateShopUrl($url, $language)
167
162
*
168
163
* @return string modified form
169
164
*/
170
- public function addShortcodeLanguageFilter ($ query_args , $ atts )
171
- {
172
- if (function_exists ('pll_current_language ' )) {
173
- $ query_args ['lang ' ] = isset ($ query_args ['lang ' ]) ?
174
- $ query_args ['lang ' ] : pll_current_language ();
175
-
176
- return $ query_args ;
165
+ public function addShortcodeLanguageFilter ($ query_args , $ atts ) {
166
+
167
+ $ ids = explode (', ' , $ atts ['ids ' ]);
168
+ $ transIds = array ();
169
+ foreach ($ ids as $ id ) {
170
+ array_push ($ transIds , pll_get_post ($ id ));
177
171
}
172
+
173
+ $ atts ['ids ' ] = $ transIds ;
174
+ $ query_args ['post__in ' ] = $ transIds ;
175
+
176
+ return $ query_args ;
178
177
}
178
+
179
179
}
0 commit comments