This topic describes how to customize list of shipping methods displayed on the checkout page.
Let’s consider a case where you need to add a collapsible text field with description for each shipping method in this list. To achieve this, you need to take the following steps:
Create a new template for the shipping method item.
Create a new template for the shipping method list.
Override the shipping step configuration.
Create new template for shipping method item
In your custom module directory, create a new file: <your_module_dir>/view/frontend/web/template/custom-method-item-template.html. In this file, add the following code.
It is copied from the <Magento_Checkout_module_dir>/view/frontend/web/template/shipping-address/shipping-method-item.html template, with the following modifications:
a <tr> element added to contain the shipping method description
a column with trigger elements that provide the collapse/expand functionality added
the entire sample wrapped in <tbody> to provide the general collapsible context for rows:
Create new template for shipping methods list
In your custom module directory, create a new file: <your_module_dir>/view/frontend/web/template/custom-method-list-template.html. In this file, add the following code. It uses the code from the app/code/Magento/Checkout/view/frontend/web/template/shipping-address/shipping-method-list.html template, with the following modifications:
a column for triggers added in <thead>
tbody moved to the item template for collapsible context
Override shipping step configuration
In your custom module directory, create a new file: <your_module_dir>/view/frontend/layout/checkout_index_index.xml. In this file, add the following code. It overrides the shippingMethodListTemplate and shippingMethodItemTemplate properties of <Magento_Checkout_module_dir>/view/frontend/web/js/view/shipping.js: