In account registration form, we have a gender field, on that there are three options as Male, Female and Others. I want to remove Others in registration form.
How can I remove that?
Any help will be appreciated!
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityYou can override this file
vendor/magento/module-customer/view/frontend/templates/widget/gender.phtml
in your custom theme here
app/design/frontend/Vendor/Theme/Magento_Customer/templates/widget/gender.phtml
Content for this file is..
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
/** @var \Magento\Customer\Block\Widget\Gender $block */
?>
<div class="field gender<?= $block->isRequired() ? ' required' : ''?>">
<label class="label" for="<?= $block->escapeHtmlAttr($block->getFieldId('gender')) ?>"><span><?= $block->escapeHtml($block->getStoreLabel('gender')) ?></span></label>
<div class="control">
<select id="<?= $block->escapeHtmlAttr($block->getFieldId('gender')) ?>" name="<?= $block->escapeHtmlAttr($block->getFieldName('gender')) ?>" title="<?= $block->escapeHtmlAttr($block->getStoreLabel('gender')) ?>"<?php if ($block->isRequired()) : ?> class="validate-select" data-validate="{required:true}"<?php endif; ?>>
<?php $options = $block->getGenderOptions(); ?>
<?php $value = $block->getGender(); ?>
<?php foreach ($options as $option) : ?>
<?php if($option->getValue() != 3): ?>
<option value="<?= $block->escapeHtmlAttr($option->getValue()) ?>"<?= ($option->getValue() == $value) ? ' selected="selected"' : '' ?>><?= $block->escapeHtml(__($option->getLabel())) ?></option>
<?php endif; ?>
<?php endforeach;?>
</select>
</div>
</div>
Hope this will help you!
Create a After plugin for vendor/magento/module-customer/Block/Widget/Gender.php
class getGenderOptions
method and remove **Others**
option from your result data.