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

Commit

Permalink
fixes #419
Browse files Browse the repository at this point in the history
allows default variation based on custom product specific attribute
  • Loading branch information
Jon007 committed May 6, 2019
1 parent 36328f1 commit a712638
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/Hyyan/WPI/Utilities.php
Expand Up @@ -256,25 +256,28 @@ public static function getDefaultAttributesTranslation($product_id, $lang = '')
$langs = array();

foreach ($default_attributes as $key => $value) {
// $term = get_term_by('slug', $value, $key);
$args = array(
'get' => 'all',
'number' => 1,
'taxonomy' => $key,
'update_term_meta_cache' => false,
'orderby' => 'none',
'suppress_filter' => true,
'slug' => $value,
'lang' => pll_get_post_language( $product_id )
);
$terms = get_terms( $args );
$term = array_shift( $terms );

if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
$terms[] = $term;
} else {
$terms[] = array($key => $value);
}
$args = array(
'get' => 'all',
'number' => 1,
'taxonomy' => $key,
'update_term_meta_cache' => false,
'orderby' => 'none',
'suppress_filter' => true,
'slug' => $value,
'lang' => pll_get_post_language( $product_id )
);
$terms = get_terms( $args );
if ( $terms && ( ! is_wp_error( $terms ) ) ) {
$term = array_shift( $terms );

if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
$terms[] = $term;
} else {
$terms[] = array($key => $value);
}
} else {
$terms = array( array( $key => $value ) );
}
}

// For each product translation, get the translated default attributes
Expand Down

0 comments on commit a712638

Please sign in to comment.