Wednesday , September 19 2018
Home >> All tutorial >> 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
Find:

  1. app/code/local/MagePsycho/Shipmentfilter/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.     
  9. </blocks>
2. Override the getShippingRates() method
File:

  1. app/code/local/MagePsycho/Shipmentfilter/Block/Onepage/Shipping/Method/Available.php:
Code:
  1. <?php
  2. /**
  3.  * @category   MagePsycho
  4.  * @package    MagePsycho_Shipmentfilter
  5.  * @author     [email protected]
  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

Here is the library of Magento Download for FREE (all versions)

Your Magento website needs a powerful Magento ERP for stock control.

DON'T MISS THE CHANCE!

magento erp

About Champ

Leave a Reply

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

Heap | Mobile and Web Analytics