Home » Magento tutorials » How to hide other shipping methods when free shipping is enabled

How to hide other shipping methods when free shipping is enabled

When free shipping method is enabled, it is shown along with other available shipping methods unlike free payment method ‘Zero Subtotal Checkout’.
There is no harm in showing other payment methods along with free shipping method. Nevertheless some merchants wants to hide rest of the methods when it is enabled.

There are many ways to do it. One of the way is to override the method:

  1. Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates()

1. Rewrite the block class

File: app/code/local/MagePsycho/Shipmentfilter/etc/config.xml:

entfilter/etc/config.xml:
Code:

  1. <blocks>
  2.     
  3.     <checkout>
  4.         <rewrite>
  5.             <onepage_shipping_method_available>MagePsycho_Shipmentfilter_Block_Onepage_Shipping_Method_Available</onepage_shipping_method_available>
  6.         </rewrite>
  7.     </checkout>
  8.     

2. Override the getShippingRates() method

File: app/code/local/MagePsycho/Shipmentfilter/Block/Onepage/Shipping/Method/Available.php

Code: 

  1. <?php
  2. /**
  3.  * @category   MagePsycho
  4.  * @package    MagePsycho_Shipmentfilter
  5.  * @author     magepsycho@gmail.com
  6.  * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
  7.  */
  8. class MagePsycho_Shipmentfilter_Block_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
  9. {
  10.     public function getShippingRates()
  11.     {
  12.         $rates = parent::getShippingRates();
  13.         if (array_key_exists(‘freeshipping’, $rates)) {
  14.             $rates = array(‘freeshipping’ => $rates['freeshipping']);
  15.         }
  16.  
  17.         return $rates;
  18.     }
  19. }

3. Refresh the cache.

 

 

About Gareth

avatar
Gareth is an editor at Tutorial Magento. His special hobby is to share magento knowledge and experience with everyone.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Scroll To Top