MailPoet 3

Add the following code to the theme functions.php file (or create a plugin for it).

12
34
5
67
8
9
10
11
12
13
14
15
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {    if (class_exists('\\MailPoet\\API\\API')) {
        $listIds = array(2); 
        $user = array(
            'email' => $form->getValue('quform_1_4')        );
 
        try {
            $subscriber = \MailPoet\API\API::MP('v1')->addSubscriber($user, $listIds);
        } catch(Exception $exception) {}
    }
 
    return $result;
}, 10, 2);
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {
    if (class_exists('\\MailPoet\\API\\API')) {
        $listIds = array(2);

        $user = array(
            'email' => $form->getValue('quform_1_4')
        );

        try {
            $subscriber = \MailPoet\API\API::MP('v1')->addSubscriber($user, $listIds);
        } catch(Exception $exception) {}
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 3, replace the number 2 with the MailPoet list ID (you can find it in the address bar when editing the list)
  • On line 6, replace 1_4 with the Email element unique ID
1
2
3
45
6
78
9
10
11
12
13
14
15
16
17
function my_mailpoet_add_subscriber(array $result, Quform_Form $form)
{
    if (class_exists('\\MailPoet\\API\\API')) {
        $listIds = array(2); 
        $user = array(
            'email' => $form->getValue('quform_1_4')        );
 
        try {
            $subscriber = \MailPoet\API\API::MP('v1')->addSubscriber($user, $listIds);
        } catch(Exception $exception) {}
    }
 
    return $result;
}
add_action('quform_post_process_1', 'my_mailpoet_add_subscriber', 10, 2);
function my_mailpoet_add_subscriber(array $result, Quform_Form $form)
{
    if (class_exists('\\MailPoet\\API\\API')) {
        $listIds = array(2);

        $user = array(
            'email' => $form->getValue('quform_1_4')
        );

        try {
            $subscriber = \MailPoet\API\API::MP('v1')->addSubscriber($user, $listIds);
        } catch(Exception $exception) {}
    }

    return $result;
}
add_action('quform_post_process_1', 'my_mailpoet_add_subscriber', 10, 2);
  • On line 4, replace the number 2 with the MailPoet list ID (you can find it in the address bar when editing the list)
  • On line 7, replace 1_4 with the Email element unique ID
  • On line 17, replace the number 1 with the form ID

Adding subscriber First name and Last name (from a “Name” element)

In the code above, find this part:

1
2
3
$user = array(
    'email' => $form->getValue('quform_1_4')
);
$user = array(
    'email' => $form->getValue('quform_1_4')
);

And replace it with this:

12
34
5
6
$name = $form->getValue('quform_1_3');$user = array(
    'email' => $form->getValue('quform_1_4'),    'first_name' => $name[2],
    'last_name' => $name[4]
);
$name = $form->getValue('quform_1_3');
$user = array(
    'email' => $form->getValue('quform_1_4'),
    'first_name' => $name[2],
    'last_name' => $name[4]
);
  • On line 1, replace 1_3 with the Name element unique ID
  • On line 3, replace 1_4 with the Email element unique ID

Adding subscriber First name and Last name (from two “Text” elements)

In the code above, find this part:

1
2
3
$user = array(
    'email' => $form->getValue('quform_1_4')
);
$user = array(
    'email' => $form->getValue('quform_1_4')
);

And replace it with this:

1
2345
$user = array(
    'email' => $form->getValue('quform_1_4'),    'first_name' => $form->getValue('quform_1_5'),    'last_name' => $form->getValue('quform_1_6'));
$user = array(
    'email' => $form->getValue('quform_1_4'),
    'first_name' => $form->getValue('quform_1_5'),
    'last_name' => $form->getValue('quform_1_6')
);
  • On line 2, replace 1_4 with the Email element unique ID
  • On line 3, replace 1_5 with the First name Text element unique ID
  • On line 4, replace 1_6 with the Last name Text element unique ID

MailPoet 2

Add the following code to the theme functions.php file (or create a plugin for it).

12
34
5
67
8
9
10
11
12
13
14
15
16
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {    if (class_exists('WYSIJA')) {
        $listIds = array(1); 
        $user = array(
            'email' => $form->getValue('quform_1_4')        );
 
        WYSIJA::get('user', 'helper')->addSubscriber(array(
            'user' => $user,
            'user_list' => array('list_ids' => $listIds)
        ));
    }
 
    return $result;
}, 10, 2);
add_action('quform_post_process_1', function (array $result, Quform_Form $form) {
    if (class_exists('WYSIJA')) {
        $listIds = array(1);

        $user = array(
            'email' => $form->getValue('quform_1_4')
        );

        WYSIJA::get('user', 'helper')->addSubscriber(array(
            'user' => $user,
            'user_list' => array('list_ids' => $listIds)
        ));
    }

    return $result;
}, 10, 2);
  • On line 1, replace the number 1 with the form ID
  • On line 3, replace the number 1 with the MailPoet list ID (you can find it in the address bar when editing the list)
  • On line 6, replace 1_4 with the Email element unique ID
1
2
3
45
6
78
9
10
11
12
13
14
15
16
17
18
function my_mailpoet_add_subscriber(array $result, Quform_Form $form)
{
    if (class_exists('WYSIJA')) {
        $listIds = array(1); 
        $user = array(
            'email' => $form->getValue('quform_1_4')        );
 
        WYSIJA::get('user', 'helper')->addSubscriber(array(
            'user' => $user,
            'user_list' => array('list_ids' => $listIds)
        ));
    }
 
    return $result;
}
add_action('quform_post_process_1', 'my_mailpoet_add_subscriber', 10, 2);
function my_mailpoet_add_subscriber(array $result, Quform_Form $form)
{
    if (class_exists('WYSIJA')) {
        $listIds = array(1);

        $user = array(
            'email' => $form->getValue('quform_1_4')
        );

        WYSIJA::get('user', 'helper')->addSubscriber(array(
            'user' => $user,
            'user_list' => array('list_ids' => $listIds)
        ));
    }

    return $result;
}
add_action('quform_post_process_1', 'my_mailpoet_add_subscriber', 10, 2);
  • On line 4, replace the number 1 with the MailPoet list ID (you can find it in the address bar when editing the list)
  • On line 7, replace 1_4 with the Email element unique ID
  • On line 18, replace the number 1 with the form ID

Adding subscriber First name and Last name (from a “Name” element)

In the code above, find this part:

1
2
3
$user = array(
    'email' => $form->getValue('quform_1_4')
);
$user = array(
    'email' => $form->getValue('quform_1_4')
);

And replace it with this:

12
34
5
6
$name = $form->getValue('quform_1_3');$user = array(
    'email' => $form->getValue('quform_1_4'),    'firstname' => $name[2],
    'lastname' => $name[4]
);
$name = $form->getValue('quform_1_3');
$user = array(
    'email' => $form->getValue('quform_1_4'),
    'firstname' => $name[2],
    'lastname' => $name[4]
);
  • On line 1, replace 1_3 with the Name element unique ID
  • On line 3, replace 1_4 with the Email element unique ID

Adding subscriber First name and Last name (from two “Text” elements)

In the code above, find this part:

1
2
3
$user = array(
    'email' => $form->getValue('quform_1_4')
);
$user = array(
    'email' => $form->getValue('quform_1_4')
);

And replace it with this:

1
2345
$user = array(
    'email' => $form->getValue('quform_1_4'),    'firstname' => $form->getValue('quform_1_5'),    'lastname' => $form->getValue('quform_1_6'));
$user = array(
    'email' => $form->getValue('quform_1_4'),
    'firstname' => $form->getValue('quform_1_5'),
    'lastname' => $form->getValue('quform_1_6')
);
  • On line 2, replace 1_4 with the Email element unique ID
  • On line 3, replace 1_5 with the First name Text element unique ID
  • On line 4, replace 1_6 with the Last name Text element unique ID
Be inspired. © 2024 ThemeCatcher Ltd. 20-22 Wenlock Road, London, England, N1 7GU | Company No. 08120384 | Built with React | Privacy Policy