I want to hide offline payment method, if some particular product is added to cart. For those special products payment should be online, So I need to hide all the offline payment method in that case.

How can I hide payment method based on condition?

  • payment methods that are used to received payment after delivery. Like COD, Cheque etc Commented Jan 25, 2017 at 7:10

2 Answers 2


At last I have found the way to hide all Offline payment methods based on product in cart Please follow the below step:

Step1 : Create a "Yes/No" product attribute with code "is_offline_payment_available" and assigned to the attribute set. This attribute is used to define that the "Offline" payment option is available or not. If it is set "Yes" "Offline" available else not available;

Step2 : Create an observer in app\code\local\YourPackage\YourModule\etc\config.xml with the below code.


Step3 :Create the observer class and method in app\code\local\YourPackage\YourModule\Model\Observer.php with the following code.


class YourPackage_YourModule_Model_Observer

  public function hideOfflinePayment($observer){
    $instance = $observer->getMethodInstance();
    $result = $observer->getResult();
    $allPaymentMethods = $config = Mage::getConfig()->getNode('default/payment')->asArray();
    foreach($allPaymentMethods as $code=>$value) {
    if (in_array($instance->getCode(), $allOfflinePayments)) {
            $cart = Mage::getSingleton('checkout/session')->getQuote();
            foreach ($cart->getAllItems() as $item) {
                $result->isAvailable = true;
               $result->isAvailable = false;

  • You can accept your own answer, too ;)
    – sv3n
    Commented Oct 19, 2017 at 7:08

+1. Just an improvement to your answer ....

$cart = Mage::getSingleton('checkout/session')->getQuote();

Can be replaced ...

$cart = $observer->getQuote();

And for performance ...

$_product = Mage::getModel('catalog/product')->load($item->getProductId());

Should be replaced with ...

$_product = $item->getProduct();

You have to add this to your etc/config.xml to access your custom attribute in quote item


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.