【发布时间】:2019-10-08 23:31:50
【问题描述】:
每当购物车中的产品数量自动增加或减少时,我都会尝试更新购物车总数。我尝试了下面的代码,但它并非一直有效,只有在购物车页面刷新后才有效;
function update_cart_refresh_update_qty() {
if (is_cart()) :
?>
<script type="text/javascript">
jQuery( function($){
$('.qty').on('change', function(){
setTimeout(function() {//This is set, so it gives the update cart button time to enable from disable mode
$('input[name="update_cart"]').trigger('click');
}, 2000);
});
});
</script>
<?php
endif;
}
add_action( 'wp_footer', 'update_cart_refresh_update_qty');
我希望每次产品数量发生变化时更新购物车总数(触发更新购物车按钮)。
提前感谢您的帮助。
【问题讨论】:
标签: php jquery wordpress woocommerce cart