受到以下问题的启发:update cart shipping woocommerce when change country with ajax,(答案无效且不正确)。
就我而言,我配置了2个运输区域:
我的意图是隐藏购物车运输计算器的更新按钮,并且在选择运输国家时,方法会自动显示。
注意::在货运计算器中,我仅激活了国家/地区,其他字段已被禁用。我不了解ajax或jquery,但是我认为这是使用ajax / jquery完成的。请对此表示感谢。
答案 0 :(得分:2)
您可以尝试使用以下内容:
add_action('wp_footer', 'cart_country_update_shipping_methods', 50);
function cart_country_update_shipping_methods() {
if ( ! is_cart() ) return; // On cart
?>
<script type='text/javascript'>
jQuery(function($){
$(document.body).on('change', 'select[name="calc_shipping_country"]', function(){
$(this).submit();
});
});
</script>
<?php
}
代码进入活动子主题(或活动主题)的functions.php文件中。经过测试,可以正常工作。
相关:Shipping calculator state field change trigger update in WooCommerce cart