[英]After woocommerce update “-” and “+” quantity buttons doesn't enable cart update button
在我的主題中,我有一個自定義的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;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.