I'm a beginner magento 2 user. Now, I want to set some default value in the shipping address's field, could you teach me what should I do? What file should I need to code?

Thank very much.

The below image is my expect result: enter image description here


In that case you need a plugin for this.

Create di.xml [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\Block\Checkout\LayoutProcessor">
        <plugin name="vendor_assign_default_value" type="Vendor\Module\Plugin\Checkout\Model\Checkout\LayoutProcessor" sortOrder="100"/>

Create LayoutProcessor.php [Vendor/Module/Plugin/Checkout/Model/Checkout/LayoutProcessor.php]

namespace Vendor\Module\Plugin\Checkout\Model\Checkout;

class LayoutProcessor
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
    public function afterProcess(
        \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
        array  $jsLayout
    ) {
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['firstname']['value'] = 'FirstName';

        ['shippingAddress']['children']['shipping-address-fieldset']['children']['company']['value'] = 'Demo Company';
        return $jsLayout;
  • 2
    This used to work, but now it does not. The First Name field has an error message though: This is a required field.
    – stephen
    Apr 6 '17 at 13:09
  • 1
    Hi Sohel, it works fine. But it's not working for email field. is there any solution for that?
    – Manish Joy
    Jun 2 '17 at 11:10
  • 1
    It is not working in Magento 2.2 throws an error This is required field
    – Moin Malek
    Nov 21 '17 at 13:32
  • 1
    @StevieG & Moin Malek Were you guys able to find the solution for "This is a required Field error." ?
    – mighty_hk
    Jul 23 '18 at 10:28
  • @SohelRana... I am using your SR/ModifiedChekout module..in that i wish to auto fill the billing address fields with default billing address for the logged in customer... How to do that ..Kindly help me May 6 '19 at 7:48

You can use free plugings which is available on magento marketplace https://marketplace.magento.com/ginbox-smartaddress.html

GINBOX robust plugin offers seamless checkout experience to online users, which allows your user to autofill shipping address fields in the checkout page by using his/her GINBOX number.

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.