问题
i have 3 zone shipping and every zone have 3 more method shipping (diffrent)
Zone US : Method Shipping = 1. Flate_rate1, 2. Flate_rate2, 3. Flate_rate3
Zone UK : Method Shipping = 1. Flate_rate4, 2. Flate_rate5, 3. Flate_rate6
Zone All WOrld : Method Shipping = 1. Flate_rate7, 2. Flate_rate8
now iwant to display method shipping by zone when select billing country with ajax.
example : if select billing country US then only display/showing method shipping by zone us (1. Flate_rate1, 2. Flate_rate2, 3. Flate_rate3)
how do that with ajax, but no refresh page.
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
回答1:
You can achieve this using the WooCommerce filter 'woocommerce_package_rates'.
You can code this way
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;
}
来源:https://stackoverflow.com/questions/39424014/update-cart-shipping-woocommerce-when-change-country-with-ajax