Skip to content

Filter Payment & Shipping Method on Checkout Page

To filter Payment Method Options  we can use observer, i assume you have knowledge of Magento module development, anyway let’s begin

  1. on config.xml, register an event
  2. .....
    <events>
    	  <payment_method_is_active>
                <observers>
                    <paymentfilter_payment_method_is_active>
                        <type>singleton</type>
                        <class>myfilter/observer</class>
                        <method>paymentMethodIsActive</method>
                    </paymentfilter_payment_method_is_active>
                </observers>
            </payment_method_is_active>  
    </events>
    .....
    
  3. create observer file app/code/local/MyModule/MyFilter/Model/Observer.php
  4. <?php
    class MyModule_MyFilter_Model_Observer {
     
        public function paymentMethodIsActive(Varien_Event_Observer $observer) {
            $event           = $observer->getEvent();
            $method          = $event->getMethodInstance();
            $result          = $event->getResult();
    
            /* remove COD payment */
    
            if($method->getCode() == 'cashondelivery' ){
                    $result->isAvailable = false;
                }else{
                    $result->isAvailable = true;
                }
            }
    
           
        }

     

 

next to filter shipping methods you have to rewirite shipping model file

  1. on config.xml file
  2. ...
    <global>
        ...
        <models>
            <shipping>
                <rewrite>
                    <shipping>MyModule_MyFilter_Model_Shipping</shipping>
                </rewrite>
            </shipping>
        </models>
        ...
    </global>
    ...
  3. create file app/code/local/MyModule/MyFilter/Model/Shipping.php
  4. <?php
    class MyModule_MyFilter_Model_Shipping extends Mage_Shipping_Model_Shipping
    {
        public function collectCarrierRates($carrierCode, $request)
        {
            if (!$this->_checkCarrierAvailability($carrierCode, $request)) {
                return $this;
            }
            return parent::collectCarrierRates($carrierCode, $request);
        }
     
        protected function _checkCarrierAvailability($carrierCode, $request = null)
        {
    	/* remove Free shipping */	
    	if($carrierCode == 'freeshipping'){ 
                    return false;
            }
    	
        }

     

 

Comments are closed.