0
votes

When setting up a variable type product in woocommerce based on product attributes, for the respective product, the front-end store provides a dropdown box where the user can pick the product attribute (ie lets say shirt size S, M or L).

At the moment that dropdown box is propagated by the attribute names, can someone please let me know where is the function located where I can make this dropdown be propagated by the names PLUS the particular attribute description?

So for instance, if the size attribute has name 'S' and description 'Small', I want the dropdown to say 'S [Small]', rather than just 'S', which is how it would be presented at the moment.

2

2 Answers

0
votes

there's a filter available for this... but currently, version 2.5.2, you can only check for its name. Which for me, not so flexible. But at least we have this...

try pasting this code to your functions.php

add_filter('woocommerce_variation_option_name','rei_variation_option_name',10,1) ;

function rei_variation_option_name($name){
    if ($name == 'S') {
        $name = 'Small';
    }
    if ($name == 'M') {
        $name = 'Medium';
    }
    if ($name == 'L') {
        $name = 'Large';
    }
    return $name;
}

Please take note that this is just for displaying it. Database has not been change.

0
votes

The solution I used, is this:

wc-template-functions.php, function wc_dropdown_variation_attribute_options

Modify:

$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term->name ) ) . '</option>';

to

$html .= '<option value="' . esc_attr( $term->slug ) . '" ' . selected( sanitize_title( $args['selected'] ), $term->slug, false ) . '>' . esc_html( apply_filters( 'woocommerce_variation_option_name', $term) ) . '</option>';

Then in functions.php, implement the following:

add_filter('woocommerce_variation_option_name','variation_option_name_description',10,1) ;
function variation_option_name_description($term){
    return $term->name.' ['.$term->description.']';
}

Thanks to Reigel for steering me in the right direction.