All we need is an easy explanation of the problem, so here it is.
I have been trying to add a placeholder in the company field of customer address edit form(edit.phtml) in Magento 2. Any suggestion or advice where should I be looking I looked into the block of 'Magento\Customer\Block\Widget\Company'
but couldn’t find anything helpful
app\design\frontend\Company_name\Magento_Customer\templates\address\edit.phtml
getLayout()->createBlock(‘Magento\Customer\Block\Widget\Company’) ?>
<?php if ($_company->isEnabled()): ?>
<?= $_company->setCompany($block->getAddress()->getCompany())->toHtml() ?>
<?php endif ?>
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
Open vendor/magento/module-customer/view/frontend/templates/widget/company.phtml
file and add placeholder
attribute in input tag.
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var \Magento\Customer\Block\Widget\Company $block */
?>
<div class="field company <?= $block->isRequired() ? 'required' : '' ?>">
<label for="company" class="label">
<span>
<?= $block->escapeHtml(__('Company')) ?>
</span>
</label>
<div class="control">
<?php
$_validationClass = $block->escapeHtmlAttr(
$this->helper(\Magento\Customer\Helper\Address::class)
->getAttributeValidationClass('company')
);
?>
<input type="text"
name="company"
id="company" placeholder="Company Placeholder"
value="<?= $block->escapeHtmlAttr($block->getCompany()) ?>"
title="<?= $block->escapeHtmlAttr(__('Company')) ?>"
class="input-text <?= $_validationClass ?: '' ?>"
>
</div>
</div>
Clear cache: php bin/magento cache:clean
Method 2
You need to check this file for company field in vendor.
vendor/magento/module-customer/view/frontend/templates/widget/company.phtml
You can override this file here in your custom theme and you can change placeholder there.
app/design/frontend/Vendor/Theme/Magento_Customer/templates/widget/company.phtml
Hope this will help you!
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂