Skip to content
This repository was archived by the owner on Mar 17, 2022. It is now read-only.

Commit c18a273

Browse files
committed
Fix #247 - Woocommerce [products] shortcode and Polylang
1 parent 0c1dc52 commit c18a273

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

src/Hyyan/WPI/Pages.php

+21-21
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,12 @@
1717
*
1818
* @author Hyyan Abo Fakher <[email protected]>
1919
*/
20-
class Pages
21-
{
20+
class Pages {
21+
2222
/**
2323
* Construct object.
2424
*/
25-
public function __construct()
26-
{
25+
public function __construct() {
2726
$method = array($this, 'getPostTranslationID');
2827
$pages = apply_filters(HooksInterface::PAGES_LIST, array(
2928
'shop',
@@ -48,10 +47,9 @@ public function __construct()
4847
/* To get product from current language in the shop page */
4948
add_filter('parse_request', array($this, 'correctShopPage'));
5049
}
51-
50+
5251
add_filter(
53-
'woocommerce_shortcode_products_query',
54-
array($this, 'addShortcodeLanguageFilter'), 10, 2
52+
'woocommerce_shortcode_products_query', array($this, 'addShortcodeLanguageFilter'), 10, 2
5553
);
5654
}
5755

@@ -62,8 +60,7 @@ public function __construct()
6260
*
6361
* @return int
6462
*/
65-
public function getPostTranslationID($id)
66-
{
63+
public function getPostTranslationID($id) {
6764
if (!function_exists('pll_get_post')) {
6865
return $id;
6966
}
@@ -85,8 +82,7 @@ public function getPostTranslationID($id)
8582
* @return bool false if the current language is the same as default
8683
* language or if the "pagename" var is empty
8784
*/
88-
public function correctShopPage(\WP $wp)
89-
{
85+
public function correctShopPage(\WP $wp) {
9086
global $polylang;
9187

9288
$shopID = wc_get_page_id('shop');
@@ -131,8 +127,7 @@ public function correctShopPage(\WP $wp)
131127
*
132128
* @return string translated url
133129
*/
134-
public function translateShopUrl($url, $language)
135-
{
130+
public function translateShopUrl($url, $language) {
136131
$result = $url;
137132

138133
if (!is_post_type_archive('product')) {
@@ -155,7 +150,7 @@ public function translateShopUrl($url, $language)
155150

156151
return $result;
157152
}
158-
153+
159154
/**
160155
* Add Shortcode Language Filter
161156
*
@@ -167,13 +162,18 @@ public function translateShopUrl($url, $language)
167162
*
168163
* @return string modified form
169164
*/
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));
177171
}
172+
173+
$atts['ids'] = $transIds;
174+
$query_args['post__in'] = $transIds;
175+
176+
return $query_args;
178177
}
178+
179179
}

0 commit comments

Comments
 (0)