Magento 1.9 – Hide Payment Method if Subtotal is Zero

magento-1.9payment-methods

We want to hide particular payment method if subtotal is zero.

We are giving 100% discount for some products, so that if customers try to buy those products, then I want to hide some custom payment method [code: hdfc]

Best Answer

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

Related Topic