Magento hide payment methods in frontend

This is the problem we need to solve: client wants to enable some payment methods for backend only. They will be displayed when he creates order in the backend but not available for customers to make order in frontend. This short tutorial will help you make a simple module to solve this problem.

First of all, you need to create an event for "payment_method_is_active"


    
	
		singleton
		paymentgroup/observer
		paymentMethodIsActive
	
    

Next, in the Observer.php file, you add a new function "paymentMethodIsActive". This function is used to filter payment methods that are not displayed in frontend.

public function paymentMethodIsActive(Varien_Event_Observer $observer) {
		$event = $observer->getEvent();
		$method = $event->getMethodInstance();
		$result = $event->getResult();		
		$result->isAvailable = true;
		$hidePaymentMethods = array('cod', 'ccsave');
		if (!empty($hidePaymentMethods)) {
			if (in_array($method->getCode(), $hidePaymentMethods)) {
				$result->isAvailable = false;
			}
		}		
	}

You can add configuration to backend for admin to select payment methods as well. That's it, very simple and easy to do. Cheers!

3 thoughts on “Magento hide payment methods in frontend”

3 Responses to Magento hide payment methods in frontend

Comments