Try this:
app/design/frontend/your_packge/your_theme/template/checkout/onepage/payment/methods.phtml
Add bellow code above file after code :foreach ($methods as $_method):
$_code = $_method->getCode();
?>
Add code in file:
<?php if(in_array($_code,array('cashondelivery','innobyte_payu_lite_cc'))):?>
<?php continue;?>
<?php endif;?>
You can add min_order_total
setting in system.xml
:
<fields>
....
<min_order_total>
<label>Minimum Order Total</label>
<frontend_type>text</frontend_type>
<sort_order>98</sort_order>
<show_in_default>1</show_in_default>
<show_in_website>1</show_in_website>
<show_in_store>0</show_in_store>
</min_order_total>
....
</fields>
Now you can see a Text box in admin Minimum Order Total
, set it's value to 1. So this method will not be shown for all orders below order total of 1.
OR if you want to disable payment method programatically, use below code :
Magento provides the isAvailable()
method in the model of the each payment method. This method tell Magento if the corresponding payment method is available or not for checkout.
Step 1 : Open the config.xml
in your custom module and do following changes:
<config>
<global>
<!-- Rewrite the Purchase order model -->
<payment>
<rewrite>
<method_purchaseorder>Myproject_Mymodule_Model_Method_Purchaseorder</method_purchaseorder>
</rewrite>
</payment>
</global>
</config>
Step 2 : Create the new Model file in your custom module at the location: app/code/local/Myproject/Mymodule/Model/Method/Purchaseorder.php
.
In this file create the isAvailable()
method as:
<?php
class Myproject_Mymodule_Model_Method_Purchaseorder extends Mage_Payment_Model_Method_Purchaseorder
{
/**
* Check if payment method is available for use
*
* @param type $quote
* @return boolean
*/
public function isAvailable($quote = null) {
//Here write your logic for enabling/disabling the method
//if this
return true;
//else
rerturn false;
}
}
Referenced from here : Dynamically Enable/Disable Payment Method
Best Answer
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.