[Magento] How to enable / disable COD depending on the city and not on the countries?


I would like to enable/disable COD option based on a particular city (seller city) rather than particular countries. How to achieve that? I have searched for this and found some topics but those are not very clear to me because this is my first magento website. Can anybody please guide me exactly how to do this? I know for this I might need to build a module so if that is the case then please guide me from scratch.

You can do this by Magento Event/Observer

First,using payment_method_is_active disable on depends current quote shippiping address /billing address city you can disable.

Code for this:

Module config.xml code:


On Observer you can get current quote shipping /billing address using below code


Observer code is:


    public function filterpaymentmethod(Varien_Event_Observer $observer) {
    /* call get payment method */
    $method = $observer->getEvent()->getMethodInstance();

    /*   get  Quote  */
    $quote = $observer->getEvent()->getQuote();
/*  check quote exit or not */
$Shipping =$observer->getEvent()->getQuote()->getShippingAddress()

        /* Disable Your payment method by city */

        if($method->getCode()=='YOUR_PAYMENT_METHOD_CODE' ){
        $result->isAvailable = false
        //  dis payment method depends on  city
            $result->isAvailable = true;
            $result->isAvailable = false;



Here the another sample of this type of works: