根据国家/地区更新Woocommerce购物车的运输方式

时间:2020-08-07 18:21:30

标签: php jquery wordpress woocommerce hook-woocommerce

受到以下问题的启发:update cart shipping woocommerce when change country with ajax,(答案无效且不正确)。

就我而言,我配置了2个运输区域:

  • 哥伦比亚-3种送货方式(免费,在目的地送货和本地送货)
  • 世界其他地方,我有一种独特的送货方式(在目的地领取)。

我的意图是隐藏购物车运输计算器的更新按钮,并且在选择运输国家时,方法会自动显示。

注意::在货运计算器中,我仅激活了国家/地区,其他字段已被禁用。我不了解ajax或jquery,但是我认为这是使用ajax / jquery完成的。请对此表示感谢。

1 个答案:

答案 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