Hello magento friends todays in this blog post im share with you to How to Add Custom Field in Newsletter Subscription in magento2 . To add a custom field to the newsletter subscription form in Magento 2, you'll need to perform a series of steps. These steps involve creating a new module and modifying certain files to achieve your goal. Here's a general outline of the process:
➤ Create a New Module:
First, create a new custom module or use an existing one. Let's call it Custom_Newsletter.
➤Create the Required Files and Directories:
Inside your module directory, create the necessary files and directories in the following structure:
app/code/Custom/Newsletter/
├── registration.php
├── etc
│ ├── module.xml
│ ├── frontend
│ │ ├── di.xml
│ │ └── events.xml
│ └── extension_attributes.xml
└── Block
└── Newsletter
└── Subscribe.php
➤ Define Your Custom Field:
<?xml version="1.0"?><config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"><type name="Magento\Newsletter\Model\Subscriber"><plugin name="custom_newsletter_subscriber_plugin" type="Custom\Newsletter\Plugin\SubscriberPlugin"/></type></config>
➤Create the Plugin Class:
➤Modify the Newsletter Subscription Form:
➤Handle Form Data:
➤Run Setup and Clear Cache:
php bin/magento setup:upgradephp bin/magento cache:cleanphp bin/magento cache:flush