How to filter payment method in onepage checkout

January 9, 2013  |  10 Comments  |  by Raj (MagePsycho)  |  Latest, Magento


Q: How will you filter the payment method in onepage checkout based on some conditions?
A: There are different ways to do so. Some of them are:
#1 By overriding template: app/design/frontend/[interface]/[theme]/template/checkout/onepage/payment/methods.phtml
#2 By overriding method: Mage_Checkout_Block_Onepage_Payment_Methods::_canUseMethod()
#3 By overriding method: Mage_Payment_Model_Method_Abstract::isAvailable()
#4 By overriding method: Mage_Checkout_Block_Onepage_Payment_Methods::getMethods()
#5 By observing event: payment_method_is_active
#6 etc.

Among above methods obviously using event-observer technique is the best way to go (#5).
And here I will be discussing about how to enable the PayPal (Website Standard) method only when current currency is USD.


Suppose a skeleton module(MagePsycho_Paymentfilter) has already been created.
1> Register the event: ‘payment_method_is_active’ in config.xml.
Add the following xml code in app/code/local/MagePsycho/Paymentfilter/etc/config.xml:


2> Implement the observer model
Create observer file: app/code/local/MagePsycho/Paymentfilter/Model/Observer.php and paste the following code:

 * @category   MagePsycho
 * @package    MagePsycho_Paymentfilter
 * @author
 * @website
 * @license  Open Software License (OSL 3.0)
class MagePsycho_Paymentfilter_Model_Observer {

	public function paymentMethodIsActive(Varien_Event_Observer $observer) {
		$event			 = $observer->getEvent();
		$method			 = $event->getMethodInstance();
		$result			 = $event->getResult();
		$currencyCode	 = Mage::app()->getStore()->getCurrentCurrencyCode();
		if( $currencyCode == 'USD'){
			if($method->getCode() == 'paypal_standard' ){
				$result->isAvailable = true;
				$result->isAvailable = false;


3> Go ahead for testing.

Happy E-Commerce!

Posted in Latest, Magento and tagged , , , , . Bookmark the permalink.

About Raj (MagePsycho)

Raj, the guy behind MagePsycho is a Zend PHP5 Certified Engineer, Magento Certified Developer, Magento Moderator / Freelancer with specialization in web applications (CMS, E-Commerce, ERP etc.). Catch him on: Twitter: @magepsycho Skype: magentopycho
  • Implementation of this observer method affects the frontend and admin pages of Magento, correct? Not just within One Page Checkout.

    In order to have it only affect one or the other,would you change the config xml to fall within the “frontend” or “admin” tags, rather than the “global” tag?

    We want all payment methods available for use by our phone sales reps, but only certain methods for online orders made by customers on the frontend.

    • Yes you are correct. Event should be registered in frontend section if you want to filter only for frontend checkout.

  • Can this be also implemented so that payment methods are shown based on Zipcode entered by users..

    • Magento Developer

      @a23dbcf6aec7ddb700492e1c19ec6ffc:disqus yes. Just you need to change the condition, for example: if( $currencyCode == ‘USD’){

  • khushbu

    i am not getting enabled cash on delivery method can i have zip file of code plz.
    thanks in advance.

  • What we’re basically doing here are three things, first we are overriding the block responsible for showing each of the payments methods on the checkout. We also add our new order status Expedite. The last part is the most interesting one, we’re registering a new class we created as an observer for the checkout_type_onepage_save_order_after event. This means that whenever Magento receives an order from the user and saves it, it automatically calls our function. This is a common pattern that you can find everywhere (native win32 application using the available windows hooks for example).

  • Manuel

    What would I need to do if I wanted to make the payment methods dependent on the shipping method that was chosen in the step before.
    The big problem is, that the payment_method_is_active Event is only dispatched when onepage is loading. After that it is not dispatched any longer, so there is no way there is any reaction to the choice of shipping.

    • Magento Developer

      Just try to capture the $_POST params in the observer and check for shipping method data. If there’s no any then try to get the shipping method from $quote object.

  • mau

    Hi, I’m trying to display a “confirm” window when the user clicks on the “continue” button at the payment method step in checkout, but only if the selected payment method is PayPal. How can I check for the selected method at this step? I did the confirm window on template/checkout/onepage/payment.phtml like this:

    __(‘Continue’) ?>


    function confirm() {
    var r = confirm(“Please confirm.”);
    if (r == true) {;
    } else {

    Thank you very much!

  • Chi Duong

    Thank for great sharing.
    I think you might also find this module helpful:
    It allows admin to set different payment as well as shipping method for different customer groups.
    Similar version’s also available on Magento 1: