0

Note: This is not a duplicate - I've searched for this and there is no specific answer to this question.

I needed to remove Name Prefix and Name Suffix fields from Customer Account. I created following 2 files under app/code/Vendor/Module/view/adminhtml/ui_component/customer_form.xml app/code/Vendor/Module/view/adminhtml/ui_component/customer_address_form.xml

and changed visibility from true to false which means these fields are not longer showing when you create a new customer in admin panel. However, when you create a new order and either select and existing customer or create a new customer, these fields are visible there and I can't seem to find any clue as to how I can remove these fields. Any help will be appreciated.enter image description here

1 Answer 1

1

Here, you can use 2 approaches to remove the given fields, 1 is by CSS or 1 is by using plugin,

Using CSS

Modify sales_order_create_index.xml Layout

create the below file in your custom module

app/code/Vendor/Module/view/adminhtml/layout/sales_order_create_index.xml

<?xml version="1.0"?>
<layout xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/layout_generic.xsd">
    <referenceBlock name="order_address_form">
        <arguments>
            <argument name="additional_classes" xsi:type="string">no-prefix no-suffix</argument>
        </arguments>
    </referenceBlock>
</layout>

After this, you can add the CSS for no-prefix and no-suffix like this in your CSS file

.no-prefix .no-siffix {
display:none;
}

Using Plugin

app/code/Vendor/Module/etc/di.xml

<type name="Magento\Sales\Model\Order\Address\Form\DataProvider">
    <plugin name="remove_prefix_suffix" type="Vendor\Module\Plugin\AddressDataProvider" />
</type>

app/code/Vendor/Module/Plugin/AddressDataProvider.php

namespace Vendor\Module\Plugin;

class AddressDataProvider
{
    public function afterGetData($subject, $result)
    {
        if (isset($result['prefix'])) {
            unset($result['prefix']);
        }
        if (isset($result['suffix'])) {
            unset($result['suffix']);
        }
        return $result;
    }
}

Let me know, if this is useful !!!

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.