使用Ajax更改国家/地区时更新购物车运输woocommerce [英] update cart shipping woocommerce when change country with ajax

查看:77
本文介绍了使用Ajax更改国家/地区时更新购物车运输woocommerce的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个区域运输,每个区域还有3个方法运输(不同)

i have 3 zone shipping and every zone have 3 more method shipping (diffrent)

  1. Zone US:方法运输= 1. Flate_rate1,2. Flate_rate2,3. Flate_rate3

  1. Zone US : Method Shipping = 1. Flate_rate1, 2. Flate_rate2, 3. Flate_rate3

Zone UK:方法运输= 1. Flate_rate4,2. Flate_rate5,3. Flate_rate6

Zone UK : Method Shipping = 1. Flate_rate4, 2. Flate_rate5, 3. Flate_rate6

区域所有工作区:方法运输= 1. Flate_rate7,2. Flate_rate8

Zone All WOrld : Method Shipping = 1. Flate_rate7, 2. Flate_rate8

现在通过区iwant到显示方法航运当选择使用Ajax帐单国家

now iwant to display method shipping by zone when select billing country with ajax.

示例:如果选择美国开票国,则仅显示/显示按地区划分的运输方式(1. Flate_rate1,2. Flate_rate2,3. Flate_rate3)

example : if select billing country US then only display/showing method shipping by zone us (1. Flate_rate1, 2. Flate_rate2, 3. Flate_rate3)

如何使用ajax进行操作,但没有刷新页面.

how do that with ajax, but no refresh page.

任何人都可以帮助我...谢谢.如果有任何帮助,您可以通过电子邮件发送:andythreesaputra@gmail.com或回答此论坛.非常感谢

any can help me... thank's.. if any help you can send by email : andythreesaputra@gmail.com or answer this forum. thank's very much

推荐答案

您可以使用WooCommerce过滤器"woocommerce_package_rates"来实现.

You can achieve this using the WooCommerce filter 'woocommerce_package_rates'.

您可以用这种方式编码

add_filter('woocommerce_package_rates', 'wf_modify_rates', 10, 3);
function wf_modify_rates($available_shipping_methods, $package){
    $methords_us = array('flaterate:1','flaterate:2');

    if( $package['destination']['country'] == 'US'){
        foreach ($available_shipping_methods as $methord_name => $methord) {
            if(!in_array($methord_name, $methords_us)){
                unset($available_shipping_methods[$methord_name]);
            }
        }
    }
    return $available_shipping_methods;
}

这篇关于使用Ajax更改国家/地区时更新购物车运输woocommerce的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆