Magento, Magento 2

How to Remove Company Field from Checkout in Magento 2

How to Remove Company Field from Checkout in Magento 2

In this tutorial, Today I will explain to how to remove company field from checkout page in Magento 2. In Magento 2, By default company field display with optional parameter. It’s not required field. So, if you want to remove it from checkout page then, you need to follow this below ways. Using that, you can customize that field in checkout page.

You may also like this :

First of all, Let’s assume that you have created simple module. Now, I am adding 3 different ways to remove company field.

1) Remove Company Field using Configuration :

For that, You need to follow this below steps in your Magento 2 admin.

  1. Login in Admin Panel.
  2. Go to Stores -> Configuration -> Customers -> Customer Configuration and expand Name and Address Options fieldset
  3. Select No in Show Company field and Save Configuration.

Note : It will remove from checkout and customer both pages.

2) Remove Company using Plugin :

First of all, You need to add plugin in di.xml at app/code/RH/Helloworld/etc/frontend/ and paste the below code :

<?xml version="1.0" ?>
<!--
/**
 * Created By : Rohan Hapani
 */
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Block\Checkout\LayoutProcessor">
        <plugin name="remove_company_from_checkout"
            type="RH\Helloworld\Plugin\Block\Checkout\LayoutProcessor"
            sortOrder="10"/>
    </type>
</config>

In addition, Create LayoutProcessor.php file at app/code/RH/Helloworld/Plugin/Block/Checkout/ and paste the below code for remove company field :

<?php
/**
 * Created By : Rohan Hapani
 */
namespace RH\Helloworld\Plugin\Block\Checkout;

class LayoutProcessor
{
    /**
     * Process js Layout of block
     *
     * @param \Magento\Checkout\Block\Checkout\LayoutProcessor $subject
     * @param array $jsLayout
     * @return array
     */
    public function afterProcess(
        \Magento\Checkout\Block\Checkout\LayoutProcessor $subject,
        array $jsLayout
    ) {
        $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']
        ['shippingAddress']['children']['shipping-address-fieldset']['children']['company']['visible'] = 0;

        return $jsLayout;
    }
}

3) Remove Company Field using Layout XML :

For that, You need to create checkout_index_index.xml file at app/code/RH/Helloworld/view/frontend/layout and paste the below code to update company field for remove on checkout page :

<?xml version="1.0"?>
<!--
/**
 * Created By : Rohan Hapani
 */
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="checkout"
    xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="checkout.root">
            <arguments>
                <argument name="jsLayout" xsi:type="array">
                    <item name="components" xsi:type="array">
                        <item name="checkout" xsi:type="array">
                            <item name="children" xsi:type="array">
                                <item name="steps" xsi:type="array">
                                    <item name="children" xsi:type="array">
                                        <item name="shipping-step" xsi:type="array">
                                            <item name="children" xsi:type="array">
                                                <item name="shippingAddress" xsi:type="array">
                                                    <item name="children" xsi:type="array">
                                                        <!-- The name of the form the field belongs to -->
                                                        <item name="shipping-address-fieldset" xsi:type="array">
                                                            <item name="children" xsi:type="array">
                                                                <item name="company" xsi:type="array">
                                                                    <item name="visible" xsi:type="boolean">false</item>
                                                                </item>
                                                            </item>
                                                        </item>
                                                    </item>
                                                </item>
                                            </item>
                                        </item>
                                    </item>
                                </item>
                            </item>
                        </item>
                    </item>
                </argument>
            </arguments>
        </referenceBlock>
    </body>
</page>

You can follow any of this above way. After that, You just need to clean cache and check it. Company field will remove successfully.

That’s it !!!

I hope this blog is easy to understand about how to remove company field from checkout page in Magento 2. In case, I missed anything or need to add some information, always feel free to leave a comment in this blog, I’ll get back with proper solution.

Keep liking and sharing !!

Tagged , ,