we are restricting the zip codes for custom shipping method....

for now we are facing problem as here :

Display the shipping charges without clicking on "check" button

so is there any other way we can allow only some zip codes and restrict other zip codes.

can we do restricting zip codes independent of shipping method

  • You can try extending collectRates method in class Mage_Shipping_Model_Shipping. I believe this is the class responsible for collecting all the shipping rates. This way, you could achieve restricting methods on the basis of zip-codes globally.
    – Prateek
    Mar 18, 2016 at 8:55
  • @Prateek can you please post the answer with code for extending the collectrates method. Mar 18, 2016 at 9:20
  • @Prateek before, you only helped me to restrict and allow only some zip codes for custom shipping method. now as we hide the shipping method, its giving problem in above link. Mar 18, 2016 at 10:07

1 Answer 1


You can go with re-write of the core Shipping model. Inside your extension config, create a re-write of that model, and in your extended model file, the content will go something like this :

class Webkul_Mpperproductshipping_Model_Shipping extends Mage_Shipping_Model_Shipping {

    public function collectRates(Mage_Shipping_Model_Rate_Request $request) {
        $storeId = $request->getStoreId();
        if (!$request->getOrig()) {
                ->setCountryId(Mage::getStoreConfig(self::XML_PATH_STORE_COUNTRY_ID, $request->getStore()))
                ->setRegionId(Mage::getStoreConfig(self::XML_PATH_STORE_REGION_ID, $request->getStore()))
                ->setCity(Mage::getStoreConfig(self::XML_PATH_STORE_CITY, $request->getStore()))
                ->setPostcode(Mage::getStoreConfig(self::XML_PATH_STORE_ZIP, $request->getStore()));

        $postCode = $request->getDestPostcode();
        $restrictedCodes = array(
        //restricted values. they can come from anywhere

        if (!in_array($postCode, $restrictedCodes)) {
            return $this;

        $limitCarrier = $request->getLimitCarrier();
        if (!$limitCarrier) {
            $carriers = Mage::getStoreConfig('carriers', $storeId);

            foreach ($carriers as $carrierCode => $carrierConfig) {
                $this->collectCarrierRates($carrierCode, $request);
        } else {
            if (!is_array($limitCarrier)) {
                $limitCarrier = array($limitCarrier);
            foreach ($limitCarrier as $carrierCode) {
                $carrierConfig = Mage::getStoreConfig('carriers/' . $carrierCode, $storeId);
                if (!$carrierConfig) {
                $this->collectCarrierRates($carrierCode, $request);

        return $this;


Basically, you are just re-writing the collectRates method of the parent class as per your requirements.

I couldn't get a chance to test the code, but it should give you some start for the point. My thoughts say that if this code is in place, you should be able to switch off globally all shipping methods in the site if destination code is not present in the array of allowed codes.

Based upon your config file, this code should replace the original models block :


And in class Webkul_Mpperproductshipping_Model_Shipping will go the above method. Don't forget to make that class a child of original Mage_Shipping_Model_Shipping class.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.