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

225
Views
Loop function not running after WooCommerce cart page update

I'm trying to run a simple loop on the WooCommerce cart page. When the page initially loads, the function does it's thing, but on update of the cart, it becomes lifeless.

Here's my loop function:

let radios = document.querySelectorAll( 'input[name="radio_options_set"]' );

simplySetAttrs();

function simplySetAttrs() {

    // I started the var at 1 to skip the first radio input
    for (var xx = 1; xx < radios.length; xx++) {
        radios[xx].setAttribute( 'onclick', 'dothisFunction( this );' );
    }
}

The only WooCommerce event that has shown any response is 'updated_cart_totals' and the radio buttons I'm targeting on the Cart page are inserted by another plugin.

Here's how I implemented it:

jQuery( document.body ).on( 'updated_cart_totals', simplySetAttrs() );

I can't get to figure out why the very basic loop doesn't take action. If I do an alert(), it works as expected, even after setting a timeout on it.

I've also tried adding different event listeners as an alternative to setting the attributes, but to no avail.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use jQuery attr to setAttribute. Try the below code.

let radios = document.querySelectorAll( 'input[name="convert_to_sub"]' );

simplySetAttrs();

function simplySetAttrs() {
    // I started the var at 1 to skip the first radio input
    for (var xx = 1; xx < radios.length; xx++) {
        jQuery(radios[xx]).attr( 'onclick', 'dothisFunction( this );' );
    }
}
about 4 years ago · Juan Pablo Isaza Report
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!