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

229
Visualizações
Make JS string replace work twice in WooCommerce

I'm using JS to string replace parts of text appended to the price.

add_filter( 'woocommerce_get_price_html', 'add_txt_to_price' );

function add_txt_to_price($price){
   global $product; 
//add text after price
    $text_to_add_after_price  = ' <span id="replace"> + VAT </span>'; //
    return  $price .   $text_to_add_after_price;
        }  

My JS

    function uge() {
    var str = document.getElementById("replace").innerHTML; 
    var res = str.replace(/VAT/gi, "Moms"); 
    document.getElementById("uge").innerHTML = res;
}

I'm adding the price a second time

add_action( 'woocommerce_after_add_to_cart_quantity', 'woocommerce_template_single_price', 31 );

and there fore the same div id is twice on the page

the string replace works fine on the price on top of the page but not the 2.

How can I make the string replace work twice for one div id?

I'm working from

https://stackoverflow.com/a/56033677

about 4 years ago · Juan Pablo Isaza
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