在我的主题中,我有一个自定义的quantity-form.php,其中我添加了两个更改产品数量的按钮 . 当我进入购物车页面时, - 按钮会更改数量,但不会启用更新购物车按钮 . 如果我通过键盘更改数量值,则会启用更新购物车按钮 . 我使用woocommerce插件 .
希望这可以帮助某人,因为这个问题是在1年前被问到的 .
这将删除页面加载时更新按钮的禁用属性,更改ajax和数量下拉列表 .
参考: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; }
1 回答
希望这可以帮助某人,因为这个问题是在1年前被问到的 .
这将删除页面加载时更新按钮的禁用属性,更改ajax和数量下拉列表 .
参考:https://gist.github.com/mikaelz/f41e29c6a99a595602e4