You can disable Company field from Checkout page using Magento 2. Company field came with Native Magento in the checkout page.
Sometimes the client doesn’t want to display extra field like company name, fax or any other unnecessary field from the checkout page.
In Magento 2 You can disable extra field like Company using XML file or by creating a plugin.
I am going to disable the company field using Plugin way.
Create Registration.php and module.xml file for declaring our new module in Magento 2. I hope you are aware of creating registration.php and module.xml file.
Create a di.xml file in frontend area of the module.
Path, app/code/Rbj/Company/etc/frontend/di.xml
<?xml version="1.0"?> <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="checkout_shipping" type="Rbj\Company\Plugin\Checkout\Model\LayoutProcessor" sortOrder="150"/> </type> </config>
Create LayoutProcessor.php file for use of around plugin for process() function.
process() function is used for render all js layout of Block in the checkout page.
<?php namespace Rbj\Company\Plugin\Checkout\Model; use Magento\Checkout\Block\Checkout\LayoutProcessor; class LayoutProcessor { public function __construct( \Magento\Payment\Model\Config $paymentModelConfig ) { $this->paymentModelConfig = $paymentModelConfig; } /* disable company from checkout page */ public function afterProcess( LayoutProcessor $subject, array $jsLayout ) { /* For Disable Company field from checkout page shipping form */ $jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children'] ['shippingAddress']['children']['shipping-address-fieldset']['children']['company'] = [ 'visible' => false ]; $activePayments = $this->paymentModelConfig->getActiveMethods(); /* For Disable company field from checkout billing form */ if (count($activePayments)) { foreach ($activePayments as $paymentCode => $payment) { $jsLayout['components']['checkout']['children']['steps']['children'] ['billing-step']['children']['payment']['children'] ['payments-list']['children'][$paymentCode.'-form']['children'] ['form-fields']['children']['company'] = [ 'visible' => false ]; } } return $jsLayout; } }
Clear Cache and check for Company field are disabled from the checkout page.