Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
WooCommerce show content after variation labels

I want to add content after variation name.

I find this hook and saw it's working before, but no on my test it's not :(

I want to ask, is there another hook/working method I can use to add content?

add_filter('woocommerce_attribute_label', 'custom_attribute_label', 10, 3);
function custom_attribute_label($label, $name, $product){
    $taxonomy = 'pa_' . $name;

    if ($taxonomy == 'pa_size')
        $label .= '<div class="custom-label">' . __('MY TEXT', 'woocommerce') . '</div>';

    return $label;
}

Code reference:
Adding a custom text next to a specific product attribute label in WooCommerce

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

If you use $label variable, it will return the name without "pa_" prefix. Some variations have "pa_" prefixes and some don't.

So you don't need to create an extra variable (i.e $taxonomy). Just use $label variable, like this:

add_filter('woocommerce_attribute_label', 'custom_attribute_label', 10, 3);

function custom_attribute_label($label, $name, $product)
{

    if ('Logo' == $label) 
    {
        $label .= '<div class="custom-label">' . __('MY TEXT', 'woocommerce') . '</div>';
    }

    return $label;
}

enter image description here


You could use switch statement for checking multiple conditions like this:

add_filter('woocommerce_attribute_label', 'custom_attribute_label', 10, 3);

function custom_attribute_label($label, $name, $product)
{

    switch ($label) 
    {
        case 'Logo':
            $label .= '<div class="custom-label">' . __('MY TEXT AFTER LOGO', 'woocommerce') . '</div>';
            break;
        case 'Color':
            $label .= '<div class="custom-label">' . __('MY TEXT AFTER COLOR', 'woocommerce') . '</div>';
            break;
    }

    return $label;
}

enter image description here

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda