Changing “Shipping Information” Label in Magento
As a seasoned e-commerce developer, I often receive queries about customizing Magento’s checkout process. One common request is to modify the default labels for billing and shipping information fields.
In this post, we’ll walk through the steps to change the “Billing Information” label to “Shipping and Billing Information” during both registration and checkout in your Magento store. Let’s dive into the solution!
Understanding the Default Label
By default, Magento uses translation files to manage labels for various elements throughout the storefront. The Billing Information label is defined in the checkout.xml file located at:
app/design/frontend/<your_package>/<your_theme>/Magento_Checkout/layout/checkout.xml
Look for this line within the <body> section of the XML file:
<block class="Magento\Checkout\Block\Checkout\LayoutProcessor" name="checkout.steps">
<action method="setStepData">
<argument name="data" xsi:type="array">
<item name="title" xsi:type="string">Billing Information</item>
</argument>
</action>
</block>
Modifying the Label
To change the label, you need to override this layout processor using a custom module. Here’s how to create and configure it:
-
Create the Custom Module: Create a new folder in the
app/codedirectory with your module name (e.g.,Company_Checkout). -
Declarative Configuration: Add the following configuration file in the
etc/module.xml:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Company_Checkout" setup_version="1.0.0">
<sequence>
<module name="Magento_Checkout"/>
</sequence>
</module>
</config>
- Layout Processor Override: Create a new file at
app/code/Company/Checkout/Observer/SetStepData.php:
namespace Company\Checkout\Observer;
use Magento\Framework\Event\ObserverInterface;
class SetStepData implements ObserverInterface
{
public function execute(\Magento\Framework\Event\Observer $observer)
{
$layoutProcessor = $observer->getLayoutProcessorsByType();
if (isset($layoutProcessor['checkoutSteps'])) {
$ checkoutSteps = $layoutProcessor['checkoutSteps'];
$billingStep = array_pop($checkoutSteps);
}
$billingStep['title'] = 'Shipping and Billing Information';
return $billingStep;
}
}
- Event Configuration: In the
app/code/Company/Checkout/etc/frontend/events.xmlfile, add:
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="checkout_steps_set_data">
<observer name="company_checkout_observer_set_step_data" instance="Company\Checkout\Observer\SetStepData"/>
</event>
</config>
- Flush Cache: After making these changes, don’t forget to flush the cache in your Magento admin panel.
Verifying the Change
Once you’ve completed these steps and flushed the cache, visit any registration or checkout page on your storefront. You should now see “Shipping and Billing Information” as the label for the billing section instead of the default “Billing Information”.
It’s essential to follow best practices when modifying Magento core files, such as using a custom module and observer pattern. This approach ensures that your changes remain intact during updates.
Remember, Magento is an open-source platform, and you can always refer to official resources like Laravel Company for more in-depth guides and tutorials on various aspects of development.
Conclusion
Changing the “Shipping Information” label in Magento requires a basic understanding of layout processors and observer pattern. By following the steps outlined above, you can easily modify this default behavior without touching any core files directly.
Don’t hesitate to explore further customizations using similar techniques for creating unique checkout experiences tailored to your business needs. If you encounter any challenges or require additional assistance, feel free to reach out to our team at Laravel Company for expert Magento development services and support!