0

I need to add some text by programmatically in 'ship to' in check out step in magento 2.2.1.

enter image description here

0
1

You cannot use static blocks or phtml files directly in html. For that you need to inject a static block in windows.checkoutConfig object with use of configProviders in Magento 2.

1) Create di.xml at

app/code/Vendor/Module/etc/frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Model\CompositeConfigProvider">
        <arguments>
            <argument name="configProviders" xsi:type="array">
                <item name="cms_block_config_provider" xsi:type="object">Vendor\Module\Model\ConfigProvider</item>
            </argument>
        </arguments>
    </type>
</config>

2) Create ConfigProvider.php to define your static block to windows.checkoutConfig

app/code/Vendor/Module/Model/ConfigProvider.php

<?php

namespace Vendor\Module\Model;

use Magento\Checkout\Model\ConfigProviderInterface;
use Magento\Framework\View\LayoutInterface;

class ConfigProvider implements ConfigProviderInterface
{
    /** @var LayoutInterface  */
    protected $_layout;

    public function __construct(LayoutInterface $layout)
    {
        $this->_layout = $layout;
    }

    public function getConfig()
    {
        $myBlockId = "my_static_block"; // CMS Block Identifier
        //$myBlockId = 20; // CMS Block ID

        return [
            'my_block_content' => $this->_layout->createBlock('Magento\Cms\Block\Block')->setBlockId($myBlockId)->toHtml()
        ];
    }
}

3) Now override shipping-information.html in your theme

app/design/frontend/{Vendor}/{theme}/Magento_Checkout/web/template/shipping-information.html

And copy this code

<div data-bind="html: window.checkoutConfig.my_block_content"></div>

Check this answer for more details: https://magento.stackexchange.com/a/176327/35758

0

You could copy and edit this template file:

Magento_Checkout/template/shipping-information.html

If you want to edit anything in the address itself you need this file:

Magento_Checkout/template/shipping-information/address-renderer/default.html
1
  • How to add the block to this file? Sanne – Bong Channarith May 25 '18 at 8:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.