Introduction
You may want to filter shipping method in onepage checkout for one of the following scenario:
- Filter shipping method based on Customer Group.
- Filter shipping method based on Country, State, Zipcode etc
- Filter shipping method based on products
Whatever may be the reason we still can filter by overriding: Mage_Shipping_Model_Shipping::collectCarrierRates()
Solution
Suppose a new module (Jeff_Shipmentfilter) has already been created. And we will be hiding flat rate shipping for non-logged in customer.
Step 1: Rewrite the shipping model class: Mage_Shipping_Model_Shipping
#app/code/local/Jeff/Shipmentfilter/etc/config.xml ..... ..... Jeff_Shipmentfilter_Model_Shipping
Step 2: Override the method: collectCarrierRates()
#app/code/local/Jeff/Shipmentfilter/Model/Shipping.php _checkCarrierAvailability($carrierCode, $request) ) { return $this; } return parent::collectCarrierRates($carrierCode, $request); } protected function _checkCarrierAvailability($carrierCode, $request) { $isLoggedIn = Mage::getSingleton('customer/session')->isLoggedIn(); if( $isLoggedIn) { if($carrierCode == 'flatrate') { return false; } } return true; } }