Skip to content

How do I add a custom checkout field ?

sfritzsche edited this page Mar 6, 2022 · 3 revisions

Version < 0.4.0

You can add your own fields through any di.xml.

<your_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="Checkout\Placeholder\Block\Onepage\PlaceholderProcessor">
        <arguments>
            <argument name="fields" xsi:type="array">
                <item name="custom_field" xsi:type="array">
                    <item name="searchKey" xsi:type="string">container_id</item>
                    <item name="path" xsi:type="string">/path/to/custom_field</item>
                </item>
            </argument>
        </arguments>
    </type>
</config>

This specification finds all fields (within the $jsLayout) that have the following path:

*/container_id/relative/path/to/custom_field

Version >= 0.4.0

You no longer need to add fields via di.xml. All fields added to the checkout layout configuration and containing a label are recognized by default. Fields that are not part of a component/are inserted by layout instruction (rendered by template) are not recognized for now.