@@ -53,6 +53,7 @@ public function __construct()
53
53
add_filter (
54
54
'woocommerce_shortcode_products_query ' , array ($ this , 'addShortcodeLanguageFilter ' ), 10 , 2
55
55
);
56
+ add_filter ( 'shortcode_atts_product_categories ' , array ( $ this , 'addShortcodeLanguageFilterCategories ' ), 10 , 4 );
56
57
}
57
58
58
59
/**
@@ -176,11 +177,35 @@ public function addShortcodeLanguageFilter($query_args, $atts)
176
177
177
178
$ atts ['ids ' ] = implode ($ transIds , ', ' );
178
179
$ query_args ['post__in ' ] = $ transIds ;
180
+ if ( isset ( $ query_args [ 'p ' ] ) && ( $ query_args [ 'p ' ] != $ transIds ) ) {
181
+ unset( $ query_args [ 'p ' ] );
182
+ }
179
183
} else {
180
184
$ query_args ['lang ' ] = isset ($ query_args ['lang ' ]) ?
181
185
$ query_args ['lang ' ] : pll_current_language ();
182
186
}
183
187
184
188
return $ query_args ;
185
189
}
190
+
191
+ public function addShortcodeLanguageFilterCategories ( $ out , $ pairs , $ atts , $ shortcode ) {
192
+
193
+ if ( isset ( $ atts [ 'ids ' ] ) && strlen ( $ atts [ 'ids ' ] ) ) {
194
+ $ ids = explode ( ', ' , $ atts [ 'ids ' ] );
195
+ $ transIds = array ();
196
+ foreach ( $ ids as $ id ) {
197
+ array_push ( $ transIds , pll_get_term ( $ id ) );
198
+ }
199
+ $ out [ 'ids ' ] = implode ( $ transIds , ', ' );
200
+ }
201
+
202
+ if ( isset ( $ atts [ 'parent ' ] ) && strlen ( $ atts [ 'parent ' ] ) ) {
203
+ $ transParent = pll_get_term ( $ atts [ 'parent ' ] );
204
+ if ( $ transParent ) {
205
+ $ out [ 'parent ' ] = $ transParent ;
206
+ }
207
+ }
208
+ return $ out ;
209
+ }
210
+
186
211
}
0 commit comments