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

Commit

Permalink
fixes #409
Browse files Browse the repository at this point in the history
allows product shortcode to translate as well as products shortcake.
Additionally allows product_categories shortcodes to automatically
translate
  • Loading branch information
Jon007 committed May 6, 2019
1 parent a712638 commit 2bf6157
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/Hyyan/WPI/Pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function __construct()
add_filter(
'woocommerce_shortcode_products_query', array($this, 'addShortcodeLanguageFilter'), 10, 2
);
add_filter( 'shortcode_atts_product_categories', array( $this, 'addShortcodeLanguageFilterCategories' ), 10, 4 );
}

/**
Expand Down Expand Up @@ -176,11 +177,35 @@ public function addShortcodeLanguageFilter($query_args, $atts)

$atts['ids'] = implode($transIds, ',');
$query_args['post__in'] = $transIds;
if ( isset( $query_args[ 'p' ] ) && ( $query_args[ 'p' ] != $transIds) ) {
unset( $query_args[ 'p' ] );
}
} else {
$query_args['lang'] = isset($query_args['lang']) ?
$query_args['lang'] : pll_current_language();
}

return $query_args;
}

public function addShortcodeLanguageFilterCategories( $out, $pairs, $atts, $shortcode ) {

if ( isset( $atts[ 'ids' ] ) && strlen( $atts[ 'ids' ] ) ) {
$ids = explode( ',', $atts[ 'ids' ] );
$transIds = array();
foreach ( $ids as $id ) {
array_push( $transIds, pll_get_term( $id ) );
}
$out[ 'ids' ] = implode( $transIds, ',' );
}

if ( isset( $atts[ 'parent' ] ) && strlen( $atts[ 'parent' ] ) ) {
$transParent = pll_get_term( $atts[ 'parent' ] );
if ( $transParent ) {
$out[ 'parent' ] = $transParent;
}
}
return $out;
}

}

0 comments on commit 2bf6157

Please sign in to comment.