Magento 2 Configuration – Set Default Value for Time Type Field

configurationdefault valuesmagento2time

How can I set a default value for a field from system.xml with type time?

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
<system>
    <section id="my_checkout" translate="label" type="text" sortOrder="100" showInDefault="1" showInWebsite="1" showInStore="1">
        <label>Checkout</label>
        <tab>my_tab</tab>
        <resource>My_Checkout::config</resource>
        <group id="cut_off_time" translate="label" sortOrder="90" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Delivery Cut-off Time</label>
            <field id="cut_off_time_start" type="time" sortOrder="10" showInDefault="1" showInWebsite="1" showInStore="1">
                <label>Start Time</label>
            </field>
        </group>
    </section>
</system>

For field "cut_off_time_start" with type TIME.

Best Answer

Try this format:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Store:etc/config.xsd">
    <default>
        <my_checkout>
            <cut_off_time>
                <cut_off_time_start>02,00,00</cut_off_time_start>
            </cut_off_time>
        </my_checkout>
    </default>
</config>
Related Topic