Merge pull request #19861 from rnaby/250418-222543-wc-product-variation

Rewritten the logic and cleaned the code.
This commit is contained in:
Claudiu Lodromanean 2018-04-26 11:46:21 -07:00 committed by GitHub
commit 0e20fb0768
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 8 deletions

View File

@ -135,16 +135,17 @@ class WC_Product_Variation extends WC_Product_Simple {
if ( isset( $attributes[ $attribute ] ) ) {
$value = $attributes[ $attribute ];
$term = taxonomy_exists( $attribute ) ? get_term_by( 'slug', $value, $attribute ) : false;
$value = ! 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 ! is_wp_error( $term ) && $term ? $term->name : $value;
}
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 '';
}
/**