Magento 2 add custom block below shipping method

Magento 2 add custom block below shipping method

Hello, this tutorial is about Magento 2 add custom block below shipping method.First of all i assume that you are an advance learner of magento 2.Hence you are here to learn how to add custom block below shipping method in one page check out in magento 2.Above all if you are not familiar with magento 2 please start from basics.

lets start our tutorial and focus on our topic. For example if you want to add custom block below shipping methods. And aslo this custom block should be inside of shipping method form. In this tutorial i will discuss in detail how we can do it. It is a four to five step method.And i would try to explain it in a simple way. So that you can do it efficiently.

The first step is to Declare module’s checkout dependency.

Declare module’s checkout dependency

First of all find the directory to your module file


and paste the below code

<?xml version="1.0"?>

<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
    <module name="QaisarSatti_HelloWorld" setup_version="0.0.1" active="true">
            <module name="Magento_Checkout"/>

Now we will move to the second step which is to Overwrite checkout layout.

Overwrite checkout layout

In the


directory, paste the below code:

<?xml version="1.0"?>
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceBlock name="checkout.root">
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="shippingAddress" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <item name="shippingAdditional" xsi:type="array">
                                                            <item name="component" xsi:type="string">uiComponent</item>
                                                            <item name="displayArea" xsi:type="string">shippingAdditional</item>
                                                            <item name="children" xsi:type="array">
                                                                <item name="additional_block" xsi:type="array">
                                                                    <item name="component" xsi:type="string">QaisarSatti_HelloWorld/js/view/checkout/shipping/additional-block</item>

similarly the the third step is to Create JavaScript UI Component.

Create JavaScript UI Component

For your information JavaScript (with Knockout)manages checkout in Magento 2 .So for that you need to create a custom JS compnent. It will create the link between checkout UI component and your custom HTML template.

in the


directory, paste the below code


], function (Component) {
    'use strict';

    return Component.extend({
        defaults: {
            template: 'QaisarSatti_HelloWorld/checkout/shipping/additional-block'

Similarly we will move to the fourth step which is to Create HTML template.

Create HTML template

Now create the HTML template wich going to be displayed in checkout.
In the


directory,use below code

<div class="checkout-block" id="block-custom">
    <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit.</p>
    <p>Cum sociis natoque penatibus et magnis dis parturient montes.</p>

Now the fifth and final step is to clear cache.

clear cache

Finally run following commands to clear cache:

php bin/magento cache:clean
php bin/magento setup:upgrade
chmod -R 777 var/*

That’s it in this tutorial. Certainly, i have tried to explain these codes and their logic in a simple way, i hope they help you learn in an easy and better way.

Since these tutorials are for learning purpose please feel free to drop any suggestions or queries in comments section. That will definitely be highly appreciated.


Recent Blogs





Leave a Reply