Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

195
Visualizações
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

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

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>
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda