i am using this following code to restrict the "cash on delivery" payment method based on pin code.


Please check code here

now if cash on delivery payment method is not visible means i want to display "cod is not available" under

payment method.

please help me to find solution.

  • 1
    please try if (!in_array($customerZip, $restrictedZips)) { throw new Mage_Core_Exception(Mage::helper('payment')->__('Code is not avaliable.')); return false; } – Amit Bera Mar 31 '15 at 8:00
  • i did what you told, check here once : pastebin.com/EX6q7zSG but i am getting error : "Exception printing is disabled by default for security reasons". please see when u r free..... – Baby in Magento Apr 1 '15 at 4:46

You referral link can only remove the code from payment list at check payment step.If you set error message at session (Mage::getSingleton('core/session')->addError(Mage::helper('payment')->__('Code is not avaliable.'))) on function isAvaliable it can be shown on next step.

According my concept it will be good idea to do something at methods.phtml where all payment method has been listing during the checkout.

    foreach ($this->getMethods() as $_method):
        $_code = $_method->getCode();
    if($_code =='cashondelivery'):
echo Mage::helper('payment')->__('Code is not avaliable.'));
  • can you please tell in which file , i have to add this code : "(Mage::getSingleton('core/session')->addError(Mage::helper('payment')->__('Code is not avaliable.')))" – Baby in Magento Apr 1 '15 at 5:35
  • i followed your code here : app/design/frontend/base/default/checkout/onepage/payment/methods.phtml. methods.phtml = > pastebin.com/B8XbJY4m but after "shipping information" it's redirecting to "checkout " page. but i did't got where to use this code : (Mage::getSingleton('core/session')->addError(Mage::helper('payment')->__('Code is not avaliable.'))) – Baby in Magento Apr 1 '15 at 6:27
  • 1
    Please use my code. Please don't use session.as I mentioned – Amit Bera Apr 1 '15 at 6:29
  • 1
    please open template hint.. check the file at checkout payment step – Amit Bera Apr 1 '15 at 6:35
  • 1
    it is not possiable to check myself. i was give idea.please do yourself... – Amit Bera Apr 1 '15 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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