Payment system management is a core of Magento store system. Handling it carefully in order to optimize the sales in the best possible way to maximize the profits and minimize the efforts is crucial. Need to disable payment method programmatically in Magento occurs when you want to show specific methods like CCAvenue to Indian Customers only or restrict Magento customer groups to use offline payment methods, etc.
One of the ways to do so is to disable payment method programmatically in Magento store based on conditions. The store owner can restrict specific payment methods based on the customer groups, product or order attributes, and shipping parameters.
Steps to disable payment method programmatically in Magento:
1. Add the below code in the config.xml file
<global> ... <events> <payment_method_is_active> <observers> <disable_paymentmethod> <class>Vendor_Extension_Model_Observer</class> <method>paymentMethodIsActive</method> </disable_paymentmethod> </observers> </payment_method_is_active> </events> ... </global>
2. Add the below code in the Observer.php file.
<?php class Vendor_Extension_Model_Observer { public function paymentMethodIsActive(Varien_Event_Observer $observer) { $method = $observer->getMethodInstance(); if ($method->getCode() == 'payment_method_code') { if (condition) { $result = $observer->getResult(); $result->isAvailable = false; } } } }
Implement these steps and control the choices of payment methods at the checkout based on different conditions!
If you are looking for the same solution in Magento 2, check disable payment method programmatically in Magento 2.
Also, do let us know your review and ratings for the solution 🙂
Thank you.