how to display the address fields in the registration form
-
14-04-2021 - |
Frage
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?
Lösung
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
Andere Tipps
I assume that all the attributes you want to show in the registration form are already introduced in Magento.
To show the address fields:
create the file
customer_account_create.xml
under app/design/frontend/[themepackage]/[theme]/Magento_Customer/layout folder.Now paste below code in this file:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
The main thing here is that you need to set true
for setShowAddressFields argument.
Please let me know if it helped.
Exact code is as follow in app/design/frontend/[themepackage]/[theme]/Magento_Customer/layout/customer_account_create.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>