How to add custom field to Shipping Address form in Magento 2 Onepage Checkout?
For example:
add select box like "Country" below phone number field
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityCreate new customer address attribute and map this attribute by xml. So after attribute creation create checkout_index_index.xml
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="checkout.root"> <arguments> <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="shipping-address-fieldset" xsi:type="array"> <item name="customer_country" xsi:type="array"> <item name="sortOrder" xsi:type="string">400</item> </item> <item name="custom_field" xsi:type="array"> <item name="sortOrder" xsi:type="string">410</item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </item> </argument> </arguments> </referenceBlock> </body> </page>
Read more about this from here
You can download example module from Here
Check out this tutorial I found for adding delivery date. For other datatypes, like select or test, you can change that in the LayoutProcessorPlugin.
http://oyenetwork.com/articles/magento2-devliery-date-module-creation-from-scratch/
You can also avoid using Observers by hooking into the OrderRepository and writing a beforeSave function.