Merge pull request #19861 from rnaby/250418-222543-wc-product-variation
Rewritten the logic and cleaned the code.
This commit is contained in:
commit
0e20fb0768
|
@ -135,16 +135,17 @@ class WC_Product_Variation extends WC_Product_Simple {
|
||||||
if ( isset( $attributes[ $attribute ] ) ) {
|
if ( isset( $attributes[ $attribute ] ) ) {
|
||||||
$value = $attributes[ $attribute ];
|
$value = $attributes[ $attribute ];
|
||||||
$term = taxonomy_exists( $attribute ) ? get_term_by( 'slug', $value, $attribute ) : false;
|
$term = taxonomy_exists( $attribute ) ? get_term_by( 'slug', $value, $attribute ) : false;
|
||||||
$value = ! is_wp_error( $term ) && $term ? $term->name : $value;
|
return ! is_wp_error( $term ) && $term ? $term->name : $value;
|
||||||
} elseif ( isset( $attributes[ 'pa_' . $attribute ] ) ) {
|
|
||||||
$value = $attributes[ 'pa_' . $attribute ];
|
|
||||||
$term = taxonomy_exists( 'pa_' . $attribute ) ? get_term_by( 'slug', $value, 'pa_' . $attribute ) : false;
|
|
||||||
$value = ! is_wp_error( $term ) && $term ? $term->name : $value;
|
|
||||||
} else {
|
|
||||||
return '';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $value;
|
$att_str = 'pa_' . $attribute;
|
||||||
|
if ( isset( $attributes[ $att_str ] ) ) {
|
||||||
|
$value = $attributes[ $att_str ];
|
||||||
|
$term = taxonomy_exists( $att_str ) ? get_term_by( 'slug', $value, $att_str ) : false;
|
||||||
|
return ! is_wp_error( $term ) && $term ? $term->name : $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue