简体   繁体   中英

After woocommerce update “-” and “+” quantity buttons doesn't enable cart update button

In my theme I have a custom quantity-form.php where I added two buttons that change product quantity. When I go to cart page the -,+ buttons change the quantity but the update cart button doesn't get enabled. If I change the quantity value via keyboard, update cart buttons gets enabled. I use the woocommerce pluggin.

Hope this will help someone as this question was asked 1 year before.

This will remove the disabled property for the update button on page load, ajax and quantity dropdown changed.

ref : https://gist.github.com/mikaelz/f41e29c6a99a595602e4

add_action( 'wp_footer', 'cart_update_qty_script', 1000);
function cart_update_qty_script() {
    if (is_cart()) :
        ?>
        <script type="text/javascript">
                jQuery(document).ready(function( $ ) {
            // Enable update cart button upon successful ajax call
            $(document).ajaxSuccess(function() {
            $( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', false );
        });
        // Enable update cart button on initial page load
        $( 'div.woocommerce > form input[name="update_cart"]' ).prop( 'disabled', false );

        // Update cart when quantity pulldown is changed
        $('body').on('change', '#quantity_pulldown', function () {
                       var quantity_selected = $("#quantity_pulldown option:selected").val();
               $('#product_quantity').val(quantity_selected);

               jQuery("[name='update_cart']").removeAttr('disabled');
               jQuery("[name='update_cart']").trigger("click");

           });

    });

      </script>
        <?php
    endif;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM