0

I'm trying to hide the field "Last Name" from the admin page, but I'm not sure what I need to change since the HTML gets populated from a JS code. I'm trying to do the exact same thing mentioned at Remove field in Customer Account Information but on Magento 2. Is this possible?

3 Answers 3

0

The fields can be found at /vendor/magento/module-customer/view/base/ui_component/customer_form.xml. To hide Last Name, open the file and set "lastname" visibility to false:

/vendor/magento/module-customer/view/base/ui_component/customer_form.xml

<field name="lastname">
    <argument name="data" xsi:type="array">
        <item name="config" xsi:type="array">
        <item name="visible" xsi:type="boolean">false</item>      
        <item name="dataType" xsi:type="string">text</item>
        <item name="formElement" xsi:type="string">input</item>
        <item name="source" xsi:type="string">customer</item>
        <item name="validation" xsi:type="array">
            <item name="required-entry" xsi:type="boolean">false</item>
        </item>
    </argument>
</field>

Afterwards, clean and flush the cache for the changes to take place.

2
  • 1
    How can you advice someone to change a code in vendor directory? How is this a good practice? Commented Jul 17, 2019 at 17:22
  • There are 3 ways to override this without toching the actual magento vendor code - 1. Using plugins 2. Using events and observers 3. Creating a custom module. Commented Jul 17, 2021 at 0:04
0

I am extending the answer given by Martin - His answer is very good and correct but changing magento core files directly is not advisable by experts. So, please do not touch core files of Magento and learn to create custom module as soon as possible.
There are 3 ways to override this without toching the actual magento vendor code - 1. Using plugins 2. Using events and observers 3. Creating a custom module.
This is the tutorial link for override.
https://youtu.be/ko75VJVor9I

0

In your custom module, create a new XML file with the same name and in the same directory structure as the original one.

The path would be app\code\VendorName\ModuleName\view\adminhtml\ui_component\customer_form.xml

In this file, you can set the visible attribute to false.

<?xml version="1.0" encoding="UTF-8"?>
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <fieldset name="customer">
        <field name="lastname">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="visible" xsi:type="boolean">false</item>
                </item>
            </argument>
        </field>
    </fieldset>
</form>

This will make the "lastname" field invisible in the customer form.

After making these changes, clear the cache and check the result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.