Replace specific attribute label text on WooCommerce variable product pages

Is it possible to change label text on “Size” and “Color” product attributes to something else on WooCommerce single variable product pages?

I tried this css code:

.single-product table.variations td.label > label{
visibility: hidden;
}
.single-product table.variations td.label > label:after {
content: 'NEW NAME';
visibility: visible;
}

But it changes both “color” and “Size” Variations. How do I separate them?

The label I want to change is pa_farge :

Source code “Chrome Developer”

Answer

2021 Update

Instead you can use the following WooCommerce dedicated filter hook to target a specific product attribute and changing its displayed label name as follows:

add_filter( 'woocommerce_attribute_label', 'custom_attribute_label', 10, 3 );
function custom_attribute_label( $label, $name, $product ) {
    // For "pa_farge" attribute taxonomy on single product pages.
    if( $name == 'pa_farge' && is_product() ) {
        $label = __('NEW NAME', 'woocommerce');
    }
    return $label;
}

Code goes in functions.php file of the active child theme (or active theme). It should works.

Leave a Reply

Your email address will not be published. Required fields are marked *