Filtering a Shipping Method in Magento
What if we want to only show a certain shipping method to certain customers?
For this we need to tap in to the
collectCarrierRates() function located in Mage_Shipping_Model_Shipping class.
Unfortunately the only way for us to do this is with a rewrite.
So, in your config.xml set up the rewrite;
Then in Model/Shipping/Shipping.php
Too much Shipping? :p
Because we only want to do the custom logic on a particular shipping carrier, and because this method is called for every available carrier, we need to first check the current carrier code is the one we want to perform our custom logic on.
if (1 == 2) with something sensible, obviously.
Why return $this?
It is a little odd but basically by returning the class in it’s current state it no longer sees this as an available shipping method (because it has not added it to its list of results).
Like this post? Share it :)