Hello Magento Friends,

In today’s blog file, we will learn about How to Add Custom Field in Newsletter Subscription in Magento 2.

A newsletter subscription helps to grow the customer base through email marketing. Grab customer attention and increase email subscribers using Magento 2 Newsletter Popup.

In default Magento, the newsletter subscription option contains only one field, i.e., email ID.

default magento newsletter

Sometimes you may need additional information from your newsletter subscribers like name, gender, city, occupation, or age.

Collecting extra details helps store owners in the following ways:

  • Effective email marketing
  • Better customer targeting
  • Improve customer engagement
  • Provide a personalized customer experience

In Magento 2, we can add custom fields in the newsletter using the below steps.

Steps to Add Custom Field in Newsletter Subscription in Magento 2:

Step 1: Create registration.php file in the given below path

{{magento_root}}\app\code\Vendor\Extension\registration.php

Now, add the following code

Step 2: Now, create module.xml file at the following path

{{magento_root}}\app\code\Vendor\Extension\etc\module.xml

Then embed the below code

Step 3: Next, create db_schema.xml at the below-mentioned path to add a custom field in the database.

{{magento_root}}\app\code\Vendor\Extension\etc\db_schema.xml

Now, add the below code-snippet

Step 4: Create default.xml file at the path mentioned underneath to display form in all pages

{{magento_root}}\app\code\Vendor\Extension\view\frontend\layout\default.xml

Now include the code as mentioned-below

Step 5: Next, create customsubscribe.phtml at the below path

{{magento_root}}\app\code\Vendor\Extension\view\frontend\templates\customsubscribe.phtml

And add the following piece of code

Step 6: Create di.xml at the below path

{{magento_root}}\app\code\Vendor\Extension\etc\di.xml

Next, incorporate the following code-snippet

Step 7: Now create plugin file SubscriptionManager.php at the following path 

{{magento_root}}\app\code\Vendor\Extension\Plugin\Newsletter\SubscriptionManager.php

Then add the below-mentioned code

Step 8: Finally, create newsletter_subscriber_block.xml at the below path to display a custom field in the admin grid.

{{magento_root}}\app\code\Vendor\Extension\view\adminhtml\layout\newsletter_subscriber_block.xml

And add the code as follows

Step 9: At last, run the below commands

Result:

When you successfully complete the above steps, an additional custom field is added to the newsletter subscription along with the email ID field.

Admin also gets the details of the custom fields in the backend newsletter subscribers grid.

Conclusion:

Hence, this way, you can add custom fields to newsletter subscription in Magento 2. If you face any difficulty in the above steps, let me know through the comment section. I will be quick to resolve your errors and queries.

Share the solution with your friends and stay in touch with us for more Magento 2 tutorials.

Happy Coding!

Click to rate this post!
[Total: 4 Average: 5]