I am programming a module where I need to set shipping to be free of charge if certain conditions are satisfied. These conditions are very specific and cannot be modelled using "Shopping cart price rules". The logic to determine whether a user should get free shipping is done but I don't know how to actually make the shipping free. I have tried this:
$address = $quote->getShippingAddress(); $address->setFreeShipping(true);
I am calling this from event handler of
It is based on the freeshipping sales rule that works with data variable
free_shipping. However, it does not work. After updating the cart, shipping keeps its nonzero cost.
I have also tried this:
$address = $quote->getShippingAddress(); $address->setShippingMethod('freeshipping_freeshipping');
It works but the problem is that free shipping must be enabled in backend for this to work. That means a user can pick it in checkout anytime - even if he shouldn't get free shipping based on my conditions.
Is there any good way set free shipping from an observer (event handler)?