B-219 Sec-55 Noida, India
+918010221733

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:

    Mage_Checkout_Block_Onepage_Shipping_Method_Available::getShippingRates()

Step 1. Rewrite the block class

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

entfilter/etc/config.xml:
Code:

    …
    <blocks>
        …
        <checkout>
            <rewrite>
                <onepage_shipping_method_available>MagePsycho_Shipmentfilter_Block_Onepage_Shipping_Method_Available</onepage_shipping_method_available>
            </rewrite>
        </checkout>
        …

Step 2. Override the getShippingRates() method

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

Code:

    <?php
    /**
     * @category   MagePsycho
     * @package    MagePsycho_Shipmentfilter
     * @author     [email protected]
     * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
     */
    class MagePsycho_Shipmentfilter_Block_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
    {
        public function getShippingRates()
        {
            $rates = parent::getShippingRates();
            if (array_key_exists(‘freeshipping’, $rates)) {
                $rates = array(‘freeshipping’ => $rates[‘freeshipping’]);
            }
    
            return $rates;
        }
    }

Step 3. Refresh the cache.

(Visited 93 times, 1 visits today)

Leave a reply

You must be logged in to post a comment.