How to force update/refresh shipping methods on checkout Magento 2 after adding discounted code (Free shipping))

How to force update/refresh shipping methods on checkout Magento 2 after adding discounted code (Free shipping))

July 5, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to force update/refresh shipping methods on checkout Magento 2 after adding discounted code (Free shipping))

Forcing an Update of Shipping Methods After Applying Free Shipping Code in Magento 2

In Magento 2, particularly when using the One Step Checkout module in version 2.2.7, you may encounter situations where applying a free shipping code (like ‘Freeship’) doesn’t automatically refresh or update the shipping methods displayed to the customer. This can lead to confusion and a poor checkout experience.

The Issue: Shipping Methods Not Refreshing After Discount Code Application

The issue lies in the fact that Magento 2’s core checkout process isn’t designed to handle this scenario out-of-the-box, especially with third-party modules like One Step Checkout installed. When you apply a free shipping code (which essentially sets the grand total to zero), the system doesn’t automatically recalculate and refresh the available shipping options.

The Solution: Manually Triggering Shipping Method Recalculation

To resolve this, you’ll need to manually trigger the recalculation of shipping methods after applying the discount code. This involves modifying the existing JavaScript logic responsible for processing the coupon application.

Here’s a step-by-step guide:

  1. First, locate the Magento_Checkout/js/model/payment/discount-messages module file. In Magento 2 setup, this is usually under vendor/magento/module-checkout/view/frontend/web/js/model/payment.

  2. Open the JavaScript file associated with this module and find the function responsible for processing the coupon application (usually a function that accepts a couponCode parameter).

  3. Within this function, after the successful application of the discount code (indicated by a positive response from the AJAX call), you need to manually trigger the recalculation of shipping methods.

  4. To do this, add the following lines:

// Assuming getPaymentInformationAction and totals are already defined in your scope
$.when(deferred).done(function () {
    fullScreenLoader.stopLoader();
    totals.isLoading(false);
    console.log("trigger update");
    // Add the following line to trigger a recalculation of shipping methods
    Magento_Checkout/js/model/quote.getItems().reloadTotals();
});

The Magento_Checkout/js/model/quote.getItems().reloadTotals() function is responsible for updating all totals and recalculating them, including the shipping rates.

The Complete Solution

Here’s the complete modified function with the added line:

return function (couponCode, isApplied) {
    var quoteId = quote.getQuoteId(),
        url = urlManager.getApplyCouponUrl(couponCode, quoteId),
        message = $t('Your coupon was successfully applied!!');

    fullScreenLoader.startLoader();

    return storage.put(
        url,
        {},
        false
    ).done(function (response) {
        var deferred;

        if (response) {
            deferred = $.Deferred();

            isApplied(true);
            totals.isLoading(true);
            getPaymentInformationAction(deferred);
            $.when(deferred).done(function () {
                fullScreenLoader.stopLoader();
                totals.isLoading(false);
                console.log("trigger update");
                Magento_Checkout/js/model/quote.getItems().reloadTotals();  // This is the added line
            });
            messageContainer.addSuccessMessage({
                'message': message
            });
        }
    }).fail(function (response) {
        fullScreenLoader.stopLoader();
        totals.isLoading(false);
        errorProcessor.process(response, messageContainer);
    });
};

Conclusion

By manually triggering the recalculation of shipping methods after applying a free shipping code in Magento 2.2.7 using One Step Checkout, you can ensure that the checkout process remains fluid and accurate for your customers.

This solution demonstrates how to modify existing JavaScript logic within the Magento ecosystem to handle edge cases that the core system doesn’t cover out-of-the-box. It’s a common practice in Magento development to extend or modify the default behavior of modules to meet specific business requirements.

Remember, this is a localized fix and may not be applicable to all versions of Magento 2 without minor adjustments. Always test changes thoroughly before deploying them to a live production environment.

For more detailed guidance on Magento development best practices and advanced customizations, consider checking out our Magento Development Resources at Laravel Company.

Magento 2 Checkout Extensions Customers

Our network