Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WooCommerce - Override Shipping Cost

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.

like image 271
BWDesign Avatar asked Jan 15 '14 20:01

BWDesign


1 Answers

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:)

like image 96
passatgt Avatar answered Nov 15 '22 13:11

passatgt