It is possible to let your subscribers add a secondary email address and send newsletters to both email addresses.
To do this,
First, create a custom field for the secondary email as shown below:-
Next, add the following PHP code snippet to your site.
add_action(
'noptin_email_sender_before_sending',
function( &$sender ) {
$recipients = array();
// Loop over the current email recipients.
foreach ( wp_parse_list( $sender->recipients ) as $recipient ) {
$subscriber = noptin_get_subscriber( $recipient );
$recipients[] = $recipient;
// If there's a subscriber matching the email address...
if ( $subscriber->exists() ) {
// Fetch their secondary email.
$secondary_email = $subscriber->get( 'secondary_email' );
if ( is_string( $secondary_email ) && is_email( $secondary_email ) ) {
$recipients[] = $secondary_email;
}
}
}
$sender->recipients = $recipients;
}
);
How it works:-
This code snippet runs just before Noptin sends an email.
It loops over the current recipients for the email and checks if they have a secondary email.
If they do, it also adds the secondary email as the address.
Tip:-
You can use any custom field label as the secondary email provided you replace line 14 in the above code snippet with the field key that was generated for your custom field.
Leave a Reply