简体   繁体   中英

Modify Shipping in Woocommerce cart

I have three countries where I will deliver the goods. I want the client to select the country first and see the delivery methods without updating the entire page, and without using the Update Totals button. Just choose the country and drop shipping options.

This code is i tried but its not working for me.

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,现在购物车/结帐部分中的某些主题没有ajax更新,因此在这种情况下,您更有可能需要制作一个自定义ajax,然后在响应中添加您所需的代码。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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