Skip to content

Commit

Permalink
ensure variation data is_array
Browse files Browse the repository at this point in the history
  • Loading branch information
Manos Psychogyiopoulos committed Aug 13, 2015
1 parent 97ab635 commit 46151c6
Showing 1 changed file with 43 additions and 40 deletions.
83 changes: 43 additions & 40 deletions includes/class-wc-product-variation.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,67 +652,70 @@ public function get_formatted_variation_attributes( $flat = false ) {
$description = array();
$return = '';

if ( ! $flat ) {
$return = '<dl class="variation">';
}

foreach ( $attributes as $attribute ) {
if ( is_array( $variation_data ) ) {

// Only deal with attributes that are variations
if ( ! $attribute[ 'is_variation' ] ) {
continue;
if ( ! $flat ) {
$return = '<dl class="variation">';
}

$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[] = '<dt>' . $description_name . ':</dt><dd>' . rawurldecode( $description_value ) . '</dd>';
}
}

if ( $flat ) {
$description[] = $description_name . ': ' . rawurldecode( $description_value );
$return .= implode( ', ', $description );
} else {
$description[] = '<dt>' . $description_name . ':</dt><dd>' . rawurldecode( $description_value ) . '</dd>';
$return .= implode( '', $description );
}
}

if ( $flat ) {
$return .= implode( ', ', $description );
} else {
$return .= implode( '', $description );
}

if ( ! $flat ) {
$return .= '</dl>';
if ( ! $flat ) {
$return .= '</dl>';
}
}

return $return;
Expand Down

0 comments on commit 46151c6

Please sign in to comment.