2

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!

2 Answers 2

3

You 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>

enter image description here

Hope this will help you!

8
  • Just want to know, can I remove the value "others" from gender attribute? Is that work?
    – MagentoDev
    Commented Nov 22, 2019 at 13:11
  • Yes, @Siva, If you'll remove that attribute value that also work. Commented Nov 22, 2019 at 13:15
  • 1
    Tried with remove the attribute value and its working great. Thanks
    – MagentoDev
    Commented Nov 23, 2019 at 4:07
  • 1
    You're welcome @Siva Commented Nov 23, 2019 at 4:11
  • 1
    Yes, you're right we don't have customer attributes in community version. Thanks for clarification!
    – MagentoDev
    Commented Nov 23, 2019 at 4:18
1

Create a After plugin for vendor/magento/module-customer/Block/Widget/Gender.php class getGenderOptions method and remove **Others** option from your result data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.