We are having a custom code to allow end user select city, date and time of his delivery. The delivery rate should change according to the city. City select box is on the checkout page.

Changing the city triggers ajax that change successfully the charge for the delivery that displayed under order review section. So far so good.
Unfortunately, the price does not reach the order after submitting the order. It gets lost somewhere.

A hint may be in the fact that the same city select box is on the product page as well, and if a user does select it when adding to cart, and just then goes to checkout, the delivery rate is displayed and does not got lost when submitting the order.

Is there any refresh needs to be triggered in order for the shipping rate to be updated?

The function that updates the rates (successfully)

function adjust_shipping_rate( $rates ){
    global $woocommerce;

        foreach ($rates as $rate) {
            $cost = $rate->cost;
            $rate->cost = $_COOKIE['shipping_city_cost'];
        return $rates;
add_filter( 'woocommerce_package_rates', 'adjust_shipping_rate', 50, 1 );

Read more here: Updating Shipping Rate on checkout page on WooCommerce site


If you know the solution of this issue, please leave us a reply in Comment section, to update the question.

Wordpress related questions and answers: