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

188
Vistas
woocommerce plus and minus button doesn't work on ajax update

i copy paste this (global/quantity-input.php) file into my theme directory. And made this changes

`

if ( ! defined( 'ABSPATH' ) ) {
    exit; // Exit if accessed directly
}
?>
<div class="quantity">
  <input class="minus" type="button" value="-">
  <input type="number" step="<?php echo esc_attr( $step ); ?>" min="<?php echo esc_attr( $min_value ); ?>" max="<?php echo esc_attr( $max_value ); ?>" name="<?php echo esc_attr( $input_name ); ?>" value="<?php echo esc_attr( $input_value ); ?>" title="<?php echo esc_attr_x( 'Qty', 'Product quantity input tooltip', 'woocommerce' ) ?>" class="input-text qty text" size="4" />
  <input class="plus" type="button" value="+">
</div>

also this jquery code into my js file.

<script type="text/javascript">
    jQuery(document).ready(function($){
        $('.quantity').on('click', '.plus', function(e) {
            $input = $(this).prev('input.qty');
            var val = parseInt($input.val());
            $input.val( val+1 ).change();
        });

        $('.quantity').on('click', '.minus', 
            function(e) {
            $input = $(this).next('input.qty');
            var val = parseInt($input.val());
            if (val > 0) {
                $input.val( val-1 ).change();
            } 
        });
    });
    </script>

it works fine but the problem is when i update any product on cart page it doesn't work anymore. is there any kind of solution? Please correct me if i did anything wrong?
Thanks

about 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

You have the first part correct. Your code will work when loading a page. But in addition to this you need to add an event for the AJAX calls.

I also added .off() so the value wont add itself multiple times after every AJAX call.

<script type="text/javascript">

jQuery(document).ajaxComplete(function(){
    jQuery('.quantity').off('click', '.plus').on('click', '.plus', function(e) {        
        $input = jQuery(this).prev('input.qty');
        var val = parseInt($input.val());
        $input.val( val+1 ).change();
    });



        jQuery('.quantity').off('click', '.minus').on('click', '.minus',
        function(e) {       
        $input = jQuery(this).next('input.qty');
        var val = parseInt($input.val());
        if (val > 1) {
            $input.val( val-1 ).change();
        }
    });
});

</script>
about 4 years ago · Santiago Trujillo 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