Great question — answering as the UphillTech team:
First on your API Response, you should need to set the cost value as custom data in WC_Session , with something like (where $value is the response cost value from your API) : if( ! WC()->session->__isset( 'shipping_cost' ) && ! empty($value) ){ WC()->session->set( 'shipping_cost', $value ); } you may need to ajax refresh checkout page using jQuery: $('body').trigger('update_checkout'); Then you will use this hooked function: add_filter('woocommerce_package_rates', 'shipping_cost_based_on_api', 12, 2); function shipping_cost_based_on_api( $rates, $package ){ if( WC()->session->__isset( 'shipping_cost' ) ) { // Loop through the shipping taxes array foreach ( $rates as $rate_key => $rate ){...
Full answer by LoicTheAztec: https://stackoverflow.stackexchange.com/a/52359365 (CC BY-SA 4.0).
Need it done for your business? UphillTech.