问题描述
受到以下问题的启发:在何时更新购物车运输woocommerce用ajax更改国家/地区,(答案无效且不正确).
Inspired by the question of: update cart shipping woocommerce when change country with ajax, (the answer does not work and is incorrect).
在我的情况下,我配置了2个运输区域:
In my case I have 2 shipping Zones configured:
- 哥伦比亚-3种送货方式(免费,在目的地送货和本地送货)
- 世界其他地方,我有一种独特的送货方式(在目的地领取).
我的意图是隐藏购物车运输计算器的更新按钮,并且在选择运输国家/地区时,方法会自动显示.
My intention is to hide the update button of the cart shipping calculator and that when selecting the shipping country the methods are automatically displayed.
注意::在货运计算器中,我仅激活了国家/地区,其他字段已被禁用.我不了解ajax或jquery,但是我认为这是使用ajax/jquery完成的.请对此表示感谢.
Note: In the shipping calculator I only have the country activated, the other fields have been deactivated. I have no knowledge of ajax or jquery, but I think this is done with ajax / jquery. Please I appreciate any help in this.
推荐答案
您可以尝试使用以下内容:
You can try to use the following:
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文件中.经过测试,可以正常工作.
Code goes in functions.php file of your active child theme (or active theme). Tested and works.
相关:运输计算器状态WooCommerce购物车中的字段更改触发器更新
这篇关于根据国家/地区更新Woocommerce购物车的运输方式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!