0

we are using Cash On Delivery Payment method in magento 1.9.0

we need this payment option only for certain zip codes/pin codes.

here someone got solution :

How to restrict default COD in magento to certain zip codes only?

i really can't able to implement that solution with some ideas.

can anyone explain me step by step in detail about that solution.

Community
  • 1
  • 1
  • Like this can I restrict, selected products purchase only from selected zip/pin codes, is it possible? – Gem Aug 12 '17 at 05:19

2 Answers2

1

All you need is to edit the file /app/code/core/Mage/Payment/Model/Method/Cashondelivery.php

Open it and add the code below to the very end of the class (just before the last “}” in the file):

public function isAvailable($quote = null)
{
    if ($quote) {

        // Here is the list of restricted Zip Codes
        $restrictedZips = array(
            '85001',
            '87965'
        );

        $address = $quote->isVirtual() ? $quote->getBillingAddress() : $quote->getShippingAddress();
        $customerZip = $address->getPostcode();

        if (in_array($customerZip, $restrictedZips)) {
            return false;
        }
    }

    return parent::isAvailable($quote);
}

P.S.: Note, that with this solution you will need to enter zip-codes right in the code. If you would like to avoid this, and get the ability to enter zip ranges via the admin's panel, contact us for more detail.

Mageworx
  • 932
  • 4
  • 7
  • here there is an option to enter list of zip codes that are restricted. but we need a solution for list of zip codes that allowed.please help us –  Mar 27 '15 at 11:37
  • how to display this pin code textfield in product view page? –  Mar 31 '15 at 04:36
  • Like this can I restrict, selected products purchase only from selected zip/pin codes, is it possible? – Gem Aug 12 '17 at 05:19
1

First you will create a zip code table in your database and the simple input field create on your product page and now create a validation for this then create a AJAX function for checking zip code COD available or not.

dvhh
  • 4,724
  • 27
  • 33
Ravi Chomal
  • 459
  • 2
  • 8
  • thanks alot, i am really not that much expert to do by your ideas. but above solution is working fro me, but i need your help here : http://magento.stackexchange.com/questions/62420/display-error-message-under-payment-method-if-cod-is-not-available?noredirect=1#comment83627_62420 –  Apr 01 '15 at 04:51
  • Like this can I restrict, selected products purchase only from selected zip/pin codes, is it possible? – Gem Aug 12 '17 at 05:20