Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

231
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda