Plugin for Subscribe() method of email subscription Magento 2.

Subscribe by Email id in Magento 2 Use Subscribe($email) method to newsletter subscription in native code.

Native Class:
Magento\Newsletter\Model\Subscriber (Magento_Newsletter)

Subscriber Class contains a list of native methods related to the subscription functionality of Magento 2.

Common functions used in Subscription Class:

  • subscribe()
  • unsubscribe()
  • confirm()
  • updateSubscription()
  • sendConfirmationRequestEmail()
  • sendConfirmationSuccessEmail()
  • beforeSave()

If you want to add some logic after subscription completed you need to create afterSubscribe() method.

Create di.xml file at Global area scope,

Create a plugin PHP file to add your custom logic after customer subscribe,

In the Plugin file, $subject contains the Subscribe Class methods.

You can add your additional logic after the subscribe method called completed using the plugin way by the given approach.