E
E
Elizaveta Krasova2020-06-02 15:13:47
JavaScript
Elizaveta Krasova, 2020-06-02 15:13:47

How to make auto-refresh in the cart when you click +/-?

Hello.
Can you please tell me how to update the cart automatically?
I found a code that works on manual input in the .qtu field, but due to my poor knowledge of js, I can’t add an update by clicking on +/- in any way. Our buttons are custom, so there are such problems.

add_action( 'wp_footer', 'cart_update_qty_script' );
function cart_update_qty_script() {
    if (is_cart()) :
    ?>
    <script>
        jQuery('div.woocommerce').on('change', '.qty', function(){
            jQuery("[name='update_cart']").trigger("click"); 
        });
    </script>
    <?php
    endif;
}

html block increase quantity
<div class="quantity">
     <input type="number" class="input-text qty text" step="1" value="3" title="Количество" size="4" placeholder="" inputmode="numeric">

     <input type="button" value="+" class="lafka-qty-plus">
     <input type="button" value="-" class="lafka-qty-minus"> 
</div>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
aleksparshkov, 2020-06-03
@ElizavetaKrasova

Try Ajax Cart AutoUpdate for WooCommerce Plugin

S
Stalker_RED, 2020-06-02
@Stalker_RED

jQuery('.lafka-qty-plus, .lafka-qty-minus').on('click', function() {
    jQuery("[name='update_cart']").trigger("click"); 
})

ugh

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question