Search Results :

×

How to Add Custom Attributes in Account Page?

In Magento 2, you can add custom attributes to the customer account page by following these steps:

  • Create a new customer attribute: Navigate to Stores > Attributes > Customer in the Magento 2 admin panel. Click on the Add New Attribute button and enter the required information for your new customer attribute. Make sure to set the Visible on Frontend option to Yes and select the appropriate Input Type for your attribute.
  • Add the attribute to the customer form: Navigate to Stores > Attributes > Customer Address in the Magento 2 admin panel. Click on the Add New Attribute button and enter the required information for your new customer address attribute. Make sure to set the Visible on Frontend option to Yes and select the appropriate Input Type for your attribute. Once you have created your customer address attribute, navigate to Stores > Configuration > Customers > Customer Configuration > Address Templates and add your new attribute to the customer address templates by editing the templates and adding the attribute code surrounded by curly braces, like so: {{custom_attribute}}.
  • Modify the customer account page template: In order to display your new attribute on the customer account page, you will need to modify the appropriate template file. Copy the customer_account_index.xml file from vendor/magento/module-customer/view/frontend/layout/ to your theme's layout directory. Then, open the file and add the following code to the body tag:
  • php
  • Copy code

  • <referenceContainer name="content">
    <block class="Magento\Customer\Block\Account\Dashboard\Info" name="customer_account_dashboard_info" template="Magento_Customer::account/dashboard/info.phtml" cacheable="false">
    <arguments>
    <argument name="label_properties" xsi:type="string">mobile_number,custom_attribute</argument >
    <argument name="view_properties" xsi:type="string">mobile_number,custom_attribute</argument >
    <argument name="data" xsi:type="array"> Mobile Number </item>
    <item name="custom_attribute" xsi:type="string">Custom Attribute </item >
    </argument>
    </arguments>
    </block>
    </referenceContainer>
    
                        



  • Replace custom_attribute with the code of your custom attribute.
  • Modify the customer account page template:
  • Copy the info.phtml file from vendor/magento/module-customer/view/frontend/templates/account/dashboard/ to your theme's templates directory. Then, open the file and add the following code where you want your custom attribute to appear:
  • php
  • Copy code

  • <?php if ($block->getCustomer()->getCustomAttribute()): ? >
    <div class="box box-information"> <strong class="box-title"> <span >
    <?= $block->escapeHtml(__('Custom Attribute')) ?> </span>
    </strong> <div class="box-content"> 
    <?= $block->escapeHtml($block->getCustomer()->getCustomAttribute()) ?>
    </div> </div> <?php endif; ?>
                         
                       

  • Replace Custom Attribute with the label of your custom attribute.

After following these steps, your custom attribute should appear on the customer account page.

1000+ Organizations That Trust Us



Contact Us


 Thank you for your response. We will get back to you soon.

Something went wrong. Please submit your query again

Hello there!

Need Help? We are right here!

support
Contact miniOrange Support
success

Thanks for your inquiry.

If you dont hear from us within 24 hours, please feel free to send a follow up email to info@xecurify.com