update cart shipping woocommerce when change country with ajax update cart shipping woocommerce when change country with ajax wordpress wordpress

update cart shipping woocommerce when change country with ajax


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;}