I am building an addon for WooCommerce that will allow the admin to set a per-customer flat rate shipping price. I am trying to hook into the function that calculates the shipping price so that I can override the calculated price and method and return only one shipping option with the pre-set price for that customer. What hook can I use to accomplish this?
I think it might be the woocommerce_calculated_shipping
hook, but I can't find a good example of how to use it.
This is probably a late answer, but if someone else needs it:
add_filter('woocommerce_package_rates','test_overwrite_fedex',100,2);
function test_overwrite_fedex($rates,$package) {
foreach ($rates as $rate) {
//Set the price
$rate->cost = 1000;
//Set the TAX
$rate->taxes[1] = 1000 * 0.2;
}
return $rates;
}
The rates are cached by Woocommerce using the wordpress transient function. So when you're testing, make sure you change the item quantity so the package rates are updated correctly, or you can empty the cart each time you refresh:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With