简体   繁体   English

在woocommerce更新后,“ - ”和“+”数量按钮不启用购物车更新按钮

[英]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. 在我的主题中,我有一个自定义的quantity-form.php,其中我添加了两个更改产品数量的按钮。 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. 我使用woocommerce插件。

Hope this will help someone as this question was asked 1 year before. 希望这可以帮助某人,因为这个问题是在1年前被问到的。

This will remove the disabled property for the update button on page load, ajax and quantity dropdown changed. 这将删除页面加载时更新按钮的禁用属性,更改ajax和数量下拉列表。

ref : https://gist.github.com/mikaelz/f41e29c6a99a595602e4 参考: 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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