variable product and additional info tab
-
Hi-looking at the additional info tab of variable products confuses me, for only the data (weight and dimensions) of one variation is shown. I suppose the data for the default variation is collected. Is this intentional?
I worked out a solution, but still the question remains.
Here is my workaround (in functions.php or plugin):// code reworked from woocommerce/classes/class-wc-cart.php // attribute slug to title if ( ! function_exists( 'attribute_slug_to_title' ) ) { function attribute_slug_to_title( $attribute ,$slug ) { global $woocommerce; if ( taxonomy_exists( esc_attr( str_replace( 'attribute_', '', $attribute ) ) ) ) { $term = get_term_by( 'slug', $slug, esc_attr( str_replace( 'attribute_', '', $attribute ) ) ); if ( ! is_wp_error( $term ) && $term->name ) $value = $term->name; } else { $value = apply_filters( 'woocommerce_variation_option_name', $value ); } return $value; } } add_filter( 'woocommerce_product_additional_information', 'tim_additional_tab', 9 ); function tim_additional_tab( $product ){ if (is_single(1155)){ remove_action( 'woocommerce_product_additional_information', 'wc_display_product_attributes', 10 ); $variations = $product->get_available_variations(); //print the whole array in additional tab and examine it //echo '<pre>'; //print_r($variations); //echo '</pre>'; //html and style to your needs and likings echo '<table class="woocommerce-product-attributes shop_attributes" style="margin-bottom:0">'; echo '<tbody>'; foreach ( $variations as $key ){ $x = array_keys($key['attributes']); $attr = $x[0]; $slug =$key['attributes'][$attr]; $attrTitle = attribute_slug_to_title($attr, $slug); echo '<tr class="woocommerce-product-attributes-item">'; echo '<th class="woocommerce-product-attributes-item__label">'.$attrTitle.'</th>'; echo '<td class="woocommerce-product-attributes-item__value">'.$key['weight_html'].' / '.$key['dimensions_html'].' / dès '.$key['display_price'].' CHF</td>'; echo '</tr>'; }//end foreach echo '</tbody>'; echo '</table>'; }//end single } /// end change additional information
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘variable product and additional info tab’ is closed to new replies.