0

We are building a wine-shop and have a few typical attributes like alcohol, sugar, acid that have values. These attributes are measured in units - e.g. alcohol in vol.%, sugar in g/litre, etc. The "additional information" tab shows the attribute names and values but just the values without the unit right after. Consequently we want to add a suffix for each attribute via a snippet/hook in functions.php and have tried with below code:

add_filter( 'woocommerce_attribute_label', 'custom_attribute_label', 10, 3 );
function custom_attribute_label( $label, $name, $product ) {
    $taxonomy = 'pa_'.$name;
    if( $taxonomy == 'alk' )
        $label .= '<span class="custom-label"> vol.%</span>';
    return $label;
}

but this does not generate any output on frontend.

Any ideas and/or feedback to solve/tweak this are appreciated!

2 Answers2

0

The condition should be if ( $taxonomy === 'pa_alk' )

Ash0ur
  • 1,505
  • 2
  • 8
  • 11
  • Thanks, but this didn't change anything - the label suffix text is still not displayed. – Wolf.Piller Jan 06 '22 at 10:36
  • 1
    it probably means that the attribute name already has the prefix 'pa_' so, try to remove this line "$taxonomy = 'pa_' . $name;" If it fails, then try adding "echo $name;" before the condition to check the attribute name – Ash0ur Jan 06 '22 at 13:20
0

I modified the code, now it's working:

add_filter( 'woocommerce_attribute_label', 'custom_attribute_label', 10, 3);
function custom_attribute_label( $label, $taxonomy, $product ) {
if( $taxonomy == 'pa_alk' )
    $label .= '<span class="custom-label"> vol.%</span>';
return $label;
}
Péter
  • 1