简体   繁体   English

WooCommerce 购物车中国家/地区更改的运费计算器自动更新

[英]Shipping calculator auto update on country change in WooCommerce cart

I woulk like to calculate on Woocommerce shipping cost based on country without clicking "Update button".我想在不点击“更新按钮”的情况下根据国家/地区计算 Woocommerce 运费。

I checked posts on forums but it did not work for me: Shipping calculator state field change trigger update in WooCommerce cart我检查了论坛上的帖子,但它对我不起作用: 运输计算器 state 字段更改触发器更新 WooCommerce 购物车

Can someone help with it?有人可以帮忙吗?

here is code I have right now:这是我现在拥有的代码:

// 1 Disable State
add_filter( 'woocommerce_shipping_calculator_enable_state', '__return_false' );
 
// 2 Disable City
add_filter( 'woocommerce_shipping_calculator_enable_city', '__return_false' );
 
// 3 Disable Postcode
add_filter( 'woocommerce_shipping_calculator_enable_postcode', '__return_false' );


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
}

www.zGruzie.cz -- this web. www.zGruzie.cz——这个 web。

You will have to use Ajax if you want to update the shipping costs without clicking the update button.如果您想在不单击更新按钮的情况下更新运费,则必须使用 Ajax。 You can read more about it in this answer .您可以在此答案中阅读更多相关信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM