wordpress woocommerce (2.6.9) override shipping

I need to dynamically get shipping costs at checkout from an external system. I’ve accessed the api and have the costs in variables and now want to ‘overwrite’ the costs coming from woocommerce with these new ones.

I’m hooking into the woocommerce_package_rates hook but don’t seem to be able to get it to work. In the example below, I’ve just swapped out the variable for a number (100) for simplicity. Any ideas?

function flat_rates_cost( $rates, $package ) {
    if ( isset( $rates['flat_rate:5'] ) ) {
        $rates['flat_rate:5']->cost = 100;
    }
    return $rates;
}
add_filter( 'woocommerce_package_rates', 'flat_rates_cost', 10, 2 );

Read more here: wordpress woocommerce (2.6.9) override shipping

Leave a Reply

Your email address will not be published. Required fields are marked *