Magento free shipping calculated on grand total

Magento free shipping calculated on grand total

August 1, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento free shipping calculated on grand total

Setting Magento Free Shipping Based on Grand Total

As an e-commerce developer, you might have encountered the situation where standard Magento shipping methods calculate free shipping based on the subtotal before tax, rather than the grand total (subtotal + tax). This can lead to inconsistencies in pricing and customer expectations. Let’s explore a clean way to achieve this without hacking the core code.

Understanding the Problem

The built-in Magento Free Shipping method uses the getPackageValueWithDiscount() method to calculate free shipping eligibility. However, this method returns the subtotal before tax, which is not always suitable for businesses that want to offer free shipping based on the final grand total price of an order.

Hacking the Core: An Unrecommended Approach

The provided solution involves directly editing the core Mage/Shipping/Model/Carrier/Freeshipping.php file and changing the line of code:

|| ($request->getPackageValueWithDiscount() >= $this->getConfigData('free_shipping_subtotal'))

To:

|| ($request->getBaseSubtotalInclTax() >= $this->getConfigData('free_shipping_subtotal'))

While this hack may work temporarily, it is not a sustainable solution. Magento core updates could overwrite your changes with future releases, and the hack introduces potential security risks by modifying core files.

A Better Solution: Using an Observer

Instead of hacking the core, we can use observers to achieve our goal without touching the core codebase. An observer allows us to intercept events triggered during Magento’s shipping calculation process.

Here’s a step-by-step guide:

  1. Create a new module in your local development environment or use an existing one.

  2. In your module’s config.xml file, add an observer for the sales_quote_collect_totals_before event:

<events>
    <sales_quote_collect_totals_before>
        <observers>
            <module_name_model_class>
                <type>singleton</type>
                <method>setFreeShippingSubtotalInclTax</method>
            </module_name_model_class>
        </observers>
    </sales_quote_collect_totals_before>
</events>

Replace module_name with your module’s name and model_class with the class that will contain the observer method.

  1. In your model file (e.g., Model/Observer.php), implement the setFreeShippingSubtotalInclTax method:
class Observer {
    public function setFreeShippingSubtotalInclTax($observer) {
        $quote = $observer->getQuote();
        // Set free_shipping_subtotal to grand total including tax
        $quote->setData('free_shipping_subtotal', $quote->getBaseSubtotalInclTax());
    }
}

This observer method intercepts the sales_quote_collect_totals_before event and sets the free_shipping_subtotal value of the quote object to the grand total including tax.

Conclusion

Offering free shipping based on the grand total in Magento requires a clean, sustainable solution that avoids hacking core files. By using observers and intercepting events during the quote totals calculation process, we can achieve our goal without compromising the integrity of the core codebase or risking conflicts with future updates.

This approach ensures better security, easier maintenance, and compatibility with future Magento versions. Always prioritize clean development practices like this when customizing your e-commerce platform.

Don’t forget to explore more articles on Laravel Company’s blog for advanced tips and best practices in Magento development!

Database Security Configuration Orders

Our network