6

I have read the other suggestions for similar problems but I have not solved my issue yet.

I'm using standard shipping (with tablerates.csv) and free shipping on orders over $50 plus a flat rate for customers that want express post.

The problem is that when a customer qualifies for free shipping the standard shipping still shows up as an option. (It should just disappear and only leave "Free" and "Express" as the 2 options.)

I am not using a "Shopping Cart Price Rule" for free shipping as this introduces a different set problems.

Can someone suggest the simplest way to stop Magento from displaying the Standard/Table rates once the free shipping threshold has been reached.

(Or even suggest an extension that solves the issue or clarify answers given to Hide other shipping methods when free shipping is enabled)

Any help would be greatly appreciated.

4
+50

Create a module with the following config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <Shipping_Onepage>
            <version>1.0.0</version>
        </Shipping_Onepage>
    </modules>
    <global>
        <blocks>
            <checkout>
                <rewrite>
                    <onepage_shipping_method_available>Shipping_Onepage_Block_Method</onepage_shipping_method_available>
                </rewrite>
            </checkout>
        </blocks>
    <global>
</config>

This is the rewritten class in Shipping/Onepage/Block/Method.php, which removes all other methods if free shipping is available:

   <?php
    class Shipping_Onepage_Block_Method 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;
    }
}

Source: http://www.blog.magepsycho.com/hide-other-shipping-methods-when-free-shipping-is-enabled/

  • 1
    in your config.xml code, ther must be </global> inplace of <global>. Check closing tag and please edit. I faced this as an issue! – Anurag Khandelwal Dec 9 '16 at 9:20
2

I always wanted to do this via observer but never managed to do it, so here is the way to do it with rewrite.

Create a module with the following etc/config.xml file:

<?xml version="1.0"?>
<config>
    <modules>
        <Your_Module>
            <version>0.0.3</version>
        </Your_Module>
    </modules>

    <global>
        <blocks>
            <checkout>
                <rewrite>
                    <onepage_shipping_method_available>Your_Module_Block_Onepage_Shipping_Method_Available</onepage_shipping_method_available>
                </rewrite>
            </checkout>
        </blocks>
    </global>
</config>

Then create the block: Block/Onepage/Shipping/Method/Available.php:

<?php
    class Your_Module_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) && array_key_exists('tablerate', $rates)) {
            unset($rates['tablerate']);
        }
        return $rates;
    }
}
1

In your theme template file app/design/frontend/[package]/[theme]/template/checkout/onepage/shipping_method/available.phtml, Find the line looks something like <dl class="sp-methods"> somewhere around line no 32. Add the below code just above the line <dl class="sp-methods">:

<?php
if( array_key_exists('freeshipping', $_shippingRateGroups )) {
$_shippingRateGroups = array('freeshipping' => $_shippingRateGroups['freeshipping']);
}
?>

And you are done

  • Default available.phtml file is located at: app/design/frontend/base/default/template/checkout/onepage/shipping_method/available.phtml – Fayyaz Khattak Dec 23 '15 at 12:58
0

I've modified Raphaels solution a bit to fit my needs. Maybe someone can use it. I needed to exclude Webshop matrixrates if UPS is already eligible for free shipping (due shopping cart price rule)

config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <MyModule_FreeShipping>
            <version>0.1.0</version>
        </MyModule_FreeShipping>
    </modules>

    <global>
        <blocks>
            <checkout>
                <rewrite>
                    <onepage_shipping_method_available>MyModule_FreeShipping_Block_Onepage_Shipping_Method_Available</onepage_shipping_method_available>
                </rewrite>
            </checkout>
        </blocks>
    </global>
</config>

Available.php

class MyModule_FreeShipping_Block_Onepage_Shipping_Method_Available extends Mage_Checkout_Block_Onepage_Shipping_Method_Available
{
    public function getShippingRates()
    {
        $rates = parent::getShippingRates();

        $free = array();

        foreach ($rates as $code => $_rates) {
            foreach ($_rates as $_rate) {
                if ($_rate->getCode() == 'ups_GND' && !$_rate->getPrice()) {
                    $free[$code] = $_rates;
                }
            }       
        }

        if (!empty($free)) {
            return $this->_rates = $free;
        }

        return $rates;
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.