在 WooCommerce 结帐时刷新运输或付款方式更改的迷你购物车
Refresh Mini cart on shipping or payment method change in WooCommerce checkout
我正在尝试在有人更改结帐页面上的送货方式或付款方式时触发 WooCommerce 迷你购物车进行更新。
我尝试使用以下代码:
add_action( 'wp_footer', 'custom_minicart_checkout_jqscript' );
function custom_minicart_checkout_jqscript() {
if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) )
return; // Only Checkout Page
?>
<script type="text/javascript">
jQuery( function($){
$('form.checkout').on('change', 'input', function(){
$(document.body).trigger('wc_fragment_refresh');
});
});
</script>
<?php
}
但是当客户对所选运输方式 or/and 付款方式进行更改时,它显示以前的总计而不是当前总计。
UPDATE 我测试了以下解决方案,但得到的结果相同。 You can see it on this video(下载视频以高质量观看)。我删除了不必要的插件并清除了 functions.php 文件。这似乎是可能的,但由于某些原因,迷你购物车更新延迟了之前的总数。
尝试改用以下方法,将更改事件委托给 document.body
并专门针对运输方式和付款方式更改:
add_action('wp_footer', 'minicart_checkout_refresh_script');
function minicart_checkout_refresh_script(){
if ( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script type="text/javascript">
(function($){
$(document.body).on('change', 'input[name="payment_method"],input[name^="shipping_method"]', function(){
$(document.body).trigger('update_checkout').trigger('wc_fragment_refresh');
});
})(jQuery);
</script>
<?php
endif;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该更好用。
Note: There is not any calculated total in mini cart, but only cart items subtotal… You can see that on WooCommerce default template cart/mini-cart.php
file. So there is nothing to be refreshed or updated in default WooCommerce mini cart on checkout page.
我正在尝试在有人更改结帐页面上的送货方式或付款方式时触发 WooCommerce 迷你购物车进行更新。
我尝试使用以下代码:
add_action( 'wp_footer', 'custom_minicart_checkout_jqscript' );
function custom_minicart_checkout_jqscript() {
if ( ! ( is_checkout() && ! is_wc_endpoint_url() ) )
return; // Only Checkout Page
?>
<script type="text/javascript">
jQuery( function($){
$('form.checkout').on('change', 'input', function(){
$(document.body).trigger('wc_fragment_refresh');
});
});
</script>
<?php
}
但是当客户对所选运输方式 or/and 付款方式进行更改时,它显示以前的总计而不是当前总计。
UPDATE 我测试了以下解决方案,但得到的结果相同。 You can see it on this video(下载视频以高质量观看)。我删除了不必要的插件并清除了 functions.php 文件。这似乎是可能的,但由于某些原因,迷你购物车更新延迟了之前的总数。
尝试改用以下方法,将更改事件委托给 document.body
并专门针对运输方式和付款方式更改:
add_action('wp_footer', 'minicart_checkout_refresh_script');
function minicart_checkout_refresh_script(){
if ( is_checkout() && ! is_wc_endpoint_url() ) :
?>
<script type="text/javascript">
(function($){
$(document.body).on('change', 'input[name="payment_method"],input[name^="shipping_method"]', function(){
$(document.body).trigger('update_checkout').trigger('wc_fragment_refresh');
});
})(jQuery);
</script>
<?php
endif;
}
代码进入活动子主题(或活动主题)的 functions.php 文件。它应该更好用。
Note: There is not any calculated total in mini cart, but only cart items subtotal… You can see that on WooCommerce default template
cart/mini-cart.php
file. So there is nothing to be refreshed or updated in default WooCommerce mini cart on checkout page.