Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!