Show a conditional message on Shipping Method Step Magento

Show a conditional message on Shipping Method Step Magento

August 28, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Show a conditional message on Shipping Method Step Magento

Displaying Conditional Shipping Disclaimer on Magento Onepage Checkout

As an e-commerce developer, I often encounter situations where clients need to display specific messages or disclaimers based on the shipping address of their customers during checkout. In this case, you want to show a message on the Shipping Method step for users with Canadian addresses, informing them about duties and taxes.

Understanding Magento’s Onepage Checkout Process

Magento’s onepage checkout is a streamlined process that condenses the entire checkout flow into a single page. The shipping method selection stage occurs after the customer has entered their shipping address but before they proceed to payment. This is where we want to display our conditional message.

Using Magento’s Shipping Address Validation

To determine if the shipping address is in Canada, we can use the built-in country code validation provided by Magento. Each address object contains a country_id attribute that corresponds with the installed country codes in your Magento instance.

Implementing the Disclaimer Message

To add this disclaimer message conditionally based on the country code, you will need to override the onepage checkout template file and modify the JavaScript responsible for rendering the shipping methods. Here’s a step-by-step guide:

  1. Override the Onepage Checkout Template

Navigate to your Magento installation and locate the app/design/frontend/[your_package]/[your_theme] folder. Create or update the checkout_onepage_shipping.html file with your custom template.

  1. Add the Disclaimer Element

Within this HTML file, add a new <div> element where you want the disclaimer message to appear. For example:

<div id="shipping-method-disclaimer" style="display: none;">
    <strong>Attention Canadian Customers:</strong> You are responsible for any duties and taxes that may apply.
</div>
  1. Modify the JavaScript

Next, you need to update the checkout.js file to include a new condition that checks the country code of the shipping address.

Find the section where shipping methods are rendered (around line 207), and add the following code:

// Check if the country is Canada
if ($('#shipping-address-selector').val() === 'CA') {
    // Show the disclaimer message
    $('#shipping-method-disclaimer').show();
} else {
    // Hide the disclaimer message for other countries
    $('#shipping-method-disclaimer').hide();
}

This JavaScript code checks if the selected shipping address is in Canada and then displays or hides the disclaimer message accordingly.

Best Practices and Further Reading

For a more robust solution, consider using Magento’s event/observer system to handle the display of this message. You can use the sales_model_service_quote_address_is_virtual event to check if the shipping address is Canadian before the checkout process begins.

To learn more about Magento’s template override structure and JavaScript integration, I recommend checking out Laravel Company’s Magento Development Guide.

Conclusion

Displaying conditional messages based on shipping addresses in Magento onepage checkout is a common requirement for e-commerce businesses. By following this guide, you can effectively add a disclaimer message for Canadian users during the shipping method selection stage.

Remember to thoroughly test your implementation under different scenarios and countries to ensure it works as expected across all edge cases.

Happy coding!

Checkout Themes Customers Pricing

Our network