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

232
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
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