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:
<global>
<events>
<payment_method_is_active>
<observers>
<paymentfilter_payment_method_is_active>
<type>singleton</type>
<class>yourmodel/observer</class>
<method>filterpaymentmethod</method>
</paymentfilter_payment_method_is_active>
</observers>
</payment_method_is_active>
</events>
</global>
On Observer you can get current quote shipping /billing address
using below code
$observer->getEvent()->getQuote()->getShippingAddress()/$observer->getEvent()->getQuote()->getBillingAddress()
Observer code is:
<?php
class YOURNANESPACE_YOURMODULE_Model_Observer {
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 */
if($quote):
$Billing=$observer->getEvent()->getQuote()->getBillingAddress();
$Shipping =$observer->getEvent()->getQuote()->getShippingAddress()
$observer->getEvent()->getQuote()->getBillingAddress();
/* Disable Your payment method by city */
if($method->getCode()=='YOUR_PAYMENT_METHOD_CODE' ){
$result->isAvailable = false
// dis payment method depends on city
if($Shipping->getCity=='YOUR_CITY'):
$result->isAvailable = true;
else:
$result->isAvailable = false;
endif;
}
endif;
}
}
Here the another sample of this type of works: