• Resolved mobizdev

    (@mobizdev)


    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:

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

    Unfortunately this does not generate any output on frontend.
    Any ideas and/or feedback to solve/tweak this are appreciated!

    The page I need help with: [log in to see the link]

Viewing 3 replies - 1 through 3 (of 3 total)
  • You could try with some simple CSS.

    For example, for the pa_alk attribute:

    .fusion-woo-additional-info-tb .woocommerce-product-attributes-item–attribute_pa_alk p::after {
    content: ” vol.%”;
    }

    Hi @mobizdev,

    I really like the CSS solution above. For the PHP snippet you’re using, $name is going to return $pa_alk so the conditional check will be for pa_pa_alk if I’m reading that correctly.

    You might try skipping that line altogether and just use something like this:

    
    if( $name == 'pa_alk' ) {
    
    }
    

    Let us know if you have any questions.

    Mirko P.

    (@rainfallnixfig)

    Hi there,

    We haven’t heard from you in a while, so I’m going to mark this as resolved. Feel free to start a new thread if you have any more questions.

    Cheers.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘how to add suffix to attribute value?’ is closed to new replies.