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

Commit 2bf6157

Browse files
committed
fixes #409
allows product shortcode to translate as well as products shortcake. Additionally allows product_categories shortcodes to automatically translate
1 parent a712638 commit 2bf6157

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

src/Hyyan/WPI/Pages.php

+25
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public function __construct()
5353
add_filter(
5454
'woocommerce_shortcode_products_query', array($this, 'addShortcodeLanguageFilter'), 10, 2
5555
);
56+
add_filter( 'shortcode_atts_product_categories', array( $this, 'addShortcodeLanguageFilterCategories' ), 10, 4 );
5657
}
5758

5859
/**
@@ -176,11 +177,35 @@ public function addShortcodeLanguageFilter($query_args, $atts)
176177

177178
$atts['ids'] = implode($transIds, ',');
178179
$query_args['post__in'] = $transIds;
180+
if ( isset( $query_args[ 'p' ] ) && ( $query_args[ 'p' ] != $transIds) ) {
181+
unset( $query_args[ 'p' ] );
182+
}
179183
} else {
180184
$query_args['lang'] = isset($query_args['lang']) ?
181185
$query_args['lang'] : pll_current_language();
182186
}
183187

184188
return $query_args;
185189
}
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+
186211
}

0 commit comments

Comments
 (0)