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

Commit a712638

Browse files
committed
fixes #419
allows default variation based on custom product specific attribute
1 parent 36328f1 commit a712638

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/Hyyan/WPI/Utilities.php

+22-19
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,28 @@ public static function getDefaultAttributesTranslation($product_id, $lang = '')
256256
$langs = array();
257257

258258
foreach ($default_attributes as $key => $value) {
259-
// $term = get_term_by('slug', $value, $key);
260-
$args = array(
261-
'get' => 'all',
262-
'number' => 1,
263-
'taxonomy' => $key,
264-
'update_term_meta_cache' => false,
265-
'orderby' => 'none',
266-
'suppress_filter' => true,
267-
'slug' => $value,
268-
'lang' => pll_get_post_language( $product_id )
269-
);
270-
$terms = get_terms( $args );
271-
$term = array_shift( $terms );
272-
273-
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
274-
$terms[] = $term;
275-
} else {
276-
$terms[] = array($key => $value);
277-
}
259+
$args = array(
260+
'get' => 'all',
261+
'number' => 1,
262+
'taxonomy' => $key,
263+
'update_term_meta_cache' => false,
264+
'orderby' => 'none',
265+
'suppress_filter' => true,
266+
'slug' => $value,
267+
'lang' => pll_get_post_language( $product_id )
268+
);
269+
$terms = get_terms( $args );
270+
if ( $terms && ( ! is_wp_error( $terms ) ) ) {
271+
$term = array_shift( $terms );
272+
273+
if ($term && pll_is_translated_taxonomy($term->taxonomy)) {
274+
$terms[] = $term;
275+
} else {
276+
$terms[] = array($key => $value);
277+
}
278+
} else {
279+
$terms = array( array( $key => $value ) );
280+
}
278281
}
279282

280283
// For each product translation, get the translated default attributes

0 commit comments

Comments
 (0)