From 98a13a0fc280d451abfb541aa2e8de782d72f1a0 Mon Sep 17 00:00:00 2001 From: Khan M Rashedun-Naby Date: Wed, 25 Apr 2018 22:54:17 +0600 Subject: [PATCH] Rewritten the logic and cleaned the code. --- includes/class-wc-product-variation.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/includes/class-wc-product-variation.php b/includes/class-wc-product-variation.php index f87d895daec..9d573a48164 100644 --- a/includes/class-wc-product-variation.php +++ b/includes/class-wc-product-variation.php @@ -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 ''; } /**