I am using woocommerce_package_rates hook on woocommerce so I could change the flat rate on checkout page, but the problem is when someone access the checkout page its not triggering everytime.

This triggers sometimes but not all the time.

add_filter( 'woocommerce_package_rates', 'custom_shipping_costs', 20, 2 );
function custom_shipping_costs( $rates, $package ) {
echo "Hello "; exit;


Any idea for the same ?

1 Answer 1


That's because the rates are cached; they should update upon an address change, or when the basket has been modified.

To force WooCommerce to fetch the latest rates, which in turn triggers your filter, add the following line of code:

add_filter('transient_shipping-transient-version', '__return_false', 10, 2);

Not the answer you're looking for? Browse other questions tagged or ask your own question.