I have to Hide Some of the Fields from shipping and Billing Adress how I can achieve this need guidance thank you
3 Answers
Step-1
please open the file Magento\Sales\Block\Adminhtml\Order\Create\Form\Address.php and check there is _prepareForm method please add below 2 lines and override the block
protected function _prepareForm()
{
'''''''''''''''''''''
$attributes = $addressForm->getAttributes();
unset($attributes['prefix']);
unset($attributes['suffix']);
.........................
}
I hope this is helpful to you!!
-
But unable to override this file, can you please tell at which layout file this block file class mentioned?– JaisaAug 28, 2020 at 19:56
I assume you are after remove a field?
Add a plugin for the Model Magento\Checkout\Block\Checkout\LayoutProcessor
<?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="layout_checkout_process" type="Mbs\ModuleName\Plugin\CheckoutLayoutProcess" />
</type>
</config>
the plugin like below:
<?php
use Magento\Checkout\Block\Checkout\LayoutProcessor;
use Magento\Framework\App\Config\ScopeConfigInterface;
class CheckoutLayoutProcess
{
/**
* @var ScopeConfigInterface
*/
private $scopeConfig;
public function __construct(
ScopeConfigInterface $scopeConfig
) {
$this->scopeConfig = $scopeConfig;
}
public function afterProcess(LayoutProcessor $subject, $jsLayout)
{
$fieldNameToRemove = 'firstname';
unset($jsLayout['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$fieldNameToRemove]);
if ($this->isBillingOnPaymentPage()) {
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']
['children']['afterMethods']['children']['billing-address-form']['children']['form-fields']['children'][$fieldNameToRemove]);
} else {
$configuration = $jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']['payment']['children']['payments-list']['children'];
foreach ($configuration as $paymentGroup => $groupConfig) {
if (isset($groupConfig['component']) and $groupConfig['component'] === 'Magento_Checkout/js/view/billing-address') {
unset($jsLayout['components']['checkout']['children']['steps']['children']['billing-step']['children']
['payment']['children']['payments-list']['children'][$paymentGroup]['children']['form-fields']['children'][$fieldNameToRemove]);
}
}
}
return $jsLayout;
}
private function isBillingOnPaymentPage()
{
return $this->scopeConfig->getValue('checkout/options/display_billing_address_on');
}
}
You need to remove a field from customer_form_attribute Table
SELECT * FROM eav_attribute
WHERE attribute_id
= 537
SELECT * FROM customer_form_attribute
WHERE attribute_id
= 537
Image Reference -> https://i.stack.imgur.com/6F8R2.png
You need to remove the form_code base on your requirement after cache clean and flush.
Note: this solution work for me.