How to disable a payment method on the frontend with Magento 1
May 24th, 2019
Warning: This post is 5 years old. Some of this information may be out of date.
Its possible in Magento to place orders via the admin area. However, some payment methods require the customer to be present at time of purchase, and so the payment method won't show in the admin area.
The correct solution for this is to use a payment method that doesn't require sensitive card details to be entered, such as a Purchase Order or Bank Transfer.
The problem with this is that if you enable the Purchase Order payment method in Magento it will also be available as a payment option in the checkout. Its not possible to disable it for the front-end via the admin area.
You can do this in code using an observer. Here's how:
Set up a new module
This might feel like overkill for something that seems simple. If you already have a module specific to your site you can simply add the observer code and configuration.
Structure:
app/code/local/Euperia
└── HidePaymentMethod
├── Helper
├── Model
│ └── Observer.php
└── etc
└── config.xml
app/etc/modules/Euperia_HidePaymentMethod.xml
Add the code
We'll start with the module setup first:
// app/etc/modules/Euperia_HidePaymentMethod.xml
<?xml version="1.0"?>
<config>
<modules>
<Euperia_HidePaymentMethod>
<active>true</active>
<codePool>local</codePool>
<depends></depends>
</Euperia_HidePaymentMethod>
</modules>
</config>
Now set up the configuration:
// app/code/local/Euperia/HidePaymentMethod/etc/config.xml
<?xml version="1.0"?>
<config>
<modules>
<Euperia_HidePaymentMethod>
<version>1.0.0</version>
</Euperia_HidePaymentMethod>
</modules>
<global>
<models>
<euperia_hidepaymentmethod>
<class>Euperia_HidePaymentMethod_Model</class>
</euperia_hidepaymentmethod>
</models>
<events>
<payment_method_is_active>
<observers>
<payment_method_hide_purchase_order>
<class>euperia_hidepaymentmethod/observer</class>
<method>hidePurchaseOrder</method>
</payment_method_hide_purchase_order>
</observers>
</payment_method_is_active>
</events>
</global>
</config>
Set up the observer:
// app/code/local/Euperia/HidePaymentMethod/Model/Observer.php
<?php
class Euperia_HidePaymentMethod_Model_Observer
{
public function hidePurchaseOrder(Varien_Event_Observer $observer)
{
if (Mage::app()->getStore()->isAdmin()) {
return;
}
$hideMethods = [
'purchaseorder',
// add additional methods here if you want to hide on frontend
];
/* call get payment method */
$method = $observer->getEvent()->getMethodInstance();
$currentMethod = strtolower($method->getCode());
if (in_array($currentMethod, $hideMethods)) {
$result = $observer->getEvent()->getResult();
$result->isAvailable = false;
}
}
}
Set up in admin area
Finally, go into your admin area and enable the payment method you want to use (in this case, the Purchase Order method). Once enabled you should clear your cache and test it.
Add item to cart, go to checkout and get to the payment section - your method shouldn't be available.
Now go into the admin area and create a new order. Once you have chosen your customer and a product you should see the Purchase Order method at the bottom. If you don't see this, try choosing a shipping method first.
← Next
Using Docker with Laravel