Plugin Contributor
Lap
(@lapzor)
Could you try again with
interests[’06af539203′] = true
and let me know if that works?
Hi Lap, unfortunately this did not work either – currently set to the following:
try {
$subscriber = $api->add_list_member( $list_id, array(
'email_address' => $email_address,
'status' => $double_optin ? 'pending' : 'subscribed',
'merge_fields' => array(
'FNAME' => $first_name,
),
'interests' => array(
// '8da648139d' => '06af539203'
interests['06af539203'] => true
)
));
Hi any other idea? Or can you please identify the way to add tags for this integration?
Plugin Contributor
Lap
(@lapzor)
Hi,,
Danny said you ether need to write your own logic to do it directly via the API, or you can use the MC4WP_Mailchimp::list_subscribe method that the plugin itself uses aswell.
$mailchimp->list_subscribe( $list_id, $subscriber->email_address, $subscriber->to_array(), $this->options['update_existing'], $this->options['replace_interests'] );
Hope that helps. If you have any questions, please let me know!
Plugin Contributor
Lap
(@lapzor)
Here is a more complete example:
$mailchimp = new MC4WP_Mailchimp();
$list_id = 'mailchimp-list-id-here';
$email_address = 'johndoe@email.com';
$vars = array(
'email_address' => $email_address,
'status' => 'pending',
'merge_fields' => array(
'FNAME' => 'John',
),
'tags' => array( 'foobar' ),
);
$mailchimp->list_subscribe($list_id, $email_address, $vars);
Hi Lap, thanks for the example – attempted to integrate in functions.php – though get hit with a fatal wordpress error
PHP Fatal error: Uncaught Error: Class ‘MC4WP_Mailchimp’ not found in (path)../functions.php:457
Is this class not being included?
Plugin Contributor
Lap
(@lapzor)
— I’m looking into this, hold on.
-
This reply was modified 3 years, 7 months ago by Lap.
Plugin Contributor
Lap
(@lapzor)
I tested the code on my setup.
It was NOT working when I use my snippets plugin because even when I set priority to 90 it still executed before MailChimp was loaded.
But when I put the test code in the end of my themes functions.php with a valid list ID and email, I receive the opt-in email as soon as I reload he page, so that was working.
Mae sure that however you include this code, that it is running later than the MailChimp plugin.
Hope that helps. If you have any questions, please let me know!
Hi Lap, thanks for looking into it.
So currently this is incorporated in my theme’s functions.php – yet the issue persists.
Here’s the thing, I’m calling this via an ajax call post page load, so maybe at that time it’s loading the snippet independent of the required plugin class? (really not sure)
Also previously utilizing $api = mc4wp('api');
worked just fine. So it’s kind of strange (note not crazy experienced in WordPress backend).
On the above basis it looks like functions included in the “mailchimp-for-wp/includes/functions.php” work no problem. So although instantiating a class instance doesn’t seem to work, this does.
Somewhat tempted to create a function within “mailchimp-for-wp/includes/functions.php”, that just instantiates the class and returns it for use:
function mc4wp_get_mailchimp() {
return new MC4WP_MailChimp();
}
Though once a update comes out – this will disappear and I don’t think this is the “recommended” approach. Any ideas?
-
This reply was modified 3 years, 7 months ago by hcohenwork.
Plugin Contributor
Lap
(@lapzor)
So you added it all the way in the bottom of your theme’s functions.php already?
Not via a code snippets plugin or some other place?
Can you send me a link to this thread on support @ mc4wp.com ?
Thanks
Resolved via support (class was case sensitive!) – thank you!
-
This reply was modified 3 years, 7 months ago by hcohenwork.
Plugin Contributor
Lap
(@lapzor)
for anyone reading along, the class name is case sensitive, and needs to be
MC4WP_MailChimp()
so
mailchimp = new MC4WP_MailChimp();
$list_id = 'mailchimp-list-id-here';
$email_address = 'johndoe@email.com';
$vars = array(
'email_address' => $email_address,
'status' => 'pending',
'merge_fields' => array(
'FNAME' => 'John',
),
'tags' => array( 'foobar' ),
);
$mailchimp->list_subscribe($list_id, $email_address, $vars);