Display Gender field as Radio button
Do you want to display the gender dropdown field as radio button in Magento 2? Then this post will definitely help you with that!
By default in Magento 2 the gender dropdown field can be shown in customer registration page, if it is configured so. This option can be configured in Magento Admin under Stores → Configuration → Customers → Customer Configuration → Name and Addresses Options. The "Show Gender" option can have 3 different values, No, Optional and Required. Let's set it to Required for our post.
Having a deeper look at the registration form template under
we can see that Magento 2 uses widgets to display customer's attributes like Gender, Name, Tax/VAT number and Date of Birth.
The gender widget code in registration form.
The gender widget template can be found under
You can easily override this template by creating a template file called gender.phtml under your theme folder like
and adding the code below
So now the registration form looks like below
And also in My Account → Account Information where the same widget template is used.
Our custom gender template can be found here.
Feel free to share this post and ask your questions in the comments below.
Till next time!