是否可以通过单击按钮来更新购物车中商品的数量并使用 ajax 重新加载?
我做了这个,但我最终只得到了更新数量而没有 ajax 调用 我该如何解决?
add_action( 'wp_footer', 'auto_update_cart_on_qty_change' );
function auto_update_cart_on_qty_change() {
if ( is_cart() ) :
?>
<script type="text/javascript">
var timeout;
jQuery( function( $ ) {
$('.woocommerce').on('change', 'input.qty', function(){
if ( timeout !== undefined ) {
clearTimeout( timeout );
}
timeout = setTimeout(function() {
$("[name='update_cart']").trigger("click");
}, 300 ); // 1 second delay, half a second (500) seems comfortable too
});
} );
</script>
<?php
endif;
}
add_action( 'wp_footer', 'button_click' );
function button_click() {
global $woocommerce;
if ( is_cart() ) :
?>
<script type="text/javascript">
jQuery( function( $ ) {
$('a#cart-update-pods').click(function() {
$('.woocommerce .quantity input[type="text"].qty').val(2);
$( document.body ).trigger( 'wc_fragments_refreshed' );
});
} );
</script>
<?php
endif;
}