How to Display Address Fields in Registration Form

custom-fieldcustomer-addressmagento-2.1registration

I was looking but I can not find a solution that will work.


During registration on Magento 2.1.11, I would like to display the following additional fields:

  • address (required)
  • mobile phone (required)
  • company name (required)
  • company's registration number (required)

It is a B2B wholesale site, so I only sell for companies. I would like all these fields to be required during registration.

maybe any have a solution?

Best Answer

Create customer_account_create.xml file your current active theme

For eg.

app/design/frontend/{YOUR_PACKAGE}/{YOUR_THEME}/Magento_Customer/layout/customer_account_create.xml

After add below code for display address field in registration form

<?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="customer_form_register">
            <action method="setShowAddressFields">
                <argument name="show.address.fields" xsi:type="boolean">true</argument>
            </action>
       </referenceBlock>
    </body>
</page>

After run below commands

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento cache:clean