diff --git a/includes/class-wc-product-variation.php b/includes/class-wc-product-variation.php index c42113ba881c6..e0f4b80029c07 100644 --- a/includes/class-wc-product-variation.php +++ b/includes/class-wc-product-variation.php @@ -652,67 +652,70 @@ public function get_formatted_variation_attributes( $flat = false ) { $description = array(); $return = ''; - if ( ! $flat ) { - $return = '
'; - } - - foreach ( $attributes as $attribute ) { + if ( is_array( $variation_data ) ) { - // Only deal with attributes that are variations - if ( ! $attribute[ 'is_variation' ] ) { - continue; + if ( ! $flat ) { + $return = '
'; } - $variation_selected_value = isset( $variation_data[ 'attribute_' . sanitize_title( $attribute[ 'name' ] ) ] ) ? $variation_data[ 'attribute_' . sanitize_title( $attribute[ 'name' ] ) ] : ''; - $description_name = esc_html( wc_attribute_label( $attribute[ 'name' ] ) ); - $description_value = __( 'Any', 'woocommerce' ); + foreach ( $attributes as $attribute ) { + + // Only deal with attributes that are variations + if ( ! $attribute[ 'is_variation' ] ) { + continue; + } + + $variation_selected_value = isset( $variation_data[ 'attribute_' . sanitize_title( $attribute[ 'name' ] ) ] ) ? $variation_data[ 'attribute_' . sanitize_title( $attribute[ 'name' ] ) ] : ''; + $description_name = esc_html( wc_attribute_label( $attribute[ 'name' ] ) ); + $description_value = __( 'Any', 'woocommerce' ); - // Get terms for attribute taxonomy or value if its a custom attribute - if ( $attribute[ 'is_taxonomy' ] ) { + // Get terms for attribute taxonomy or value if its a custom attribute + if ( $attribute[ 'is_taxonomy' ] ) { - $post_terms = wp_get_post_terms( $this->id, $attribute[ 'name' ] ); + $post_terms = wp_get_post_terms( $this->id, $attribute[ 'name' ] ); - foreach ( $post_terms as $term ) { - if ( $variation_selected_value === $term->slug ) { - $description_value = apply_filters( 'woocommerce_variation_option_name', esc_html( $term->name ) ); + foreach ( $post_terms as $term ) { + if ( $variation_selected_value === $term->slug ) { + $description_value = apply_filters( 'woocommerce_variation_option_name', esc_html( $term->name ) ); + } } - } - } else { + } else { - $options = wc_get_text_attributes( $attribute[ 'value' ] ); + $options = wc_get_text_attributes( $attribute[ 'value' ] ); - foreach ( $options as $option ) { + foreach ( $options as $option ) { - if ( sanitize_title( $variation_selected_value ) === $variation_selected_value ) { - if ( $variation_selected_value !== sanitize_title( $option ) ) { - continue; - } - } else { - if ( $variation_selected_value !== $option ) { - continue; + if ( sanitize_title( $variation_selected_value ) === $variation_selected_value ) { + if ( $variation_selected_value !== sanitize_title( $option ) ) { + continue; + } + } else { + if ( $variation_selected_value !== $option ) { + continue; + } } + + $description_value = esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); } + } - $description_value = esc_html( apply_filters( 'woocommerce_variation_option_name', $option ) ); + if ( $flat ) { + $description[] = $description_name . ': ' . rawurldecode( $description_value ); + } else { + $description[] = '
' . $description_name . ':
' . rawurldecode( $description_value ) . '
'; } } if ( $flat ) { - $description[] = $description_name . ': ' . rawurldecode( $description_value ); + $return .= implode( ', ', $description ); } else { - $description[] = '
' . $description_name . ':
' . rawurldecode( $description_value ) . '
'; + $return .= implode( '', $description ); } - } - if ( $flat ) { - $return .= implode( ', ', $description ); - } else { - $return .= implode( '', $description ); - } - - if ( ! $flat ) { - $return .= '
'; + if ( ! $flat ) { + $return .= '
'; + } } return $return;