latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Custom profile and Mailchimp

Home Forums Community Forum Custom profile and Mailchimp

This topic contains 8 replies, has 2 voices. Last updated by  Cristián Lávaque 3 years, 4 months ago.

Topic Author Topic
Posted: Tuesday Aug 20th, 2013 at 1:03 am #56216

I have searched extensively and for many hours for an answer and cannot find it in these forums. What is required to have the custom profile data to be sent to Mailchimp when a user registers? I have added the API and list code to S2 member. I have added custom fields to S2m and when a user registers the data is saved in WP perfectly. Only the new user’s names and email address is sent to mailchimp. Do you have to put the custom field name or data ID into mailchimp somewhere? Do the field names in WP have to be in a certain format for mailchimp to take their data, such as all caps, a maximum length, etc? I have seen some posts that discuss more detailed programming, but the instruction in S2m Options don’t mention any of that. Thanks in advance for your help.

List Of Topic Replies

Viewing 8 replies - 1 through 8 (of 8 total)
Author Replies
Author Replies
Posted: Thursday Aug 22nd, 2013 at 1:40 am #56403

Custom profile fields are not something s2Member includes when sending the user data to MailChimp, that’s why it’s not described in the integration’s documentation, it needs a customization similar to the one you found in other threads to achieve it.

When you created the custom profile field, you gave it an ID. You can get the value of that field for the user using that id with the function get_user_field. http://s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field%28%29

Here’s an example with two custom fields I made up (country, phone):

Create this dir/file: /wp-content/mu-plugins/s2-hacks.php
See Knowledge Base » Hacking s2Member® Via Hooks/Filters

[hilite pre_code]
get_user_field('country', $vars['user_id']),
'phone' => get_user_field('phone', $vars['user_id']),
);

return array_merge($merge, $custom_merge);
}
[/hilite]

So you’d use your own custom field IDs instead of the ones I put in the example, and you can add more if you have more than two.

I hope that helps. :)

Posted: Thursday Aug 22nd, 2013 at 9:39 am #56442

Thank you for the clarification, however I followed your instructions and the data did not get into Mailchimp. I created the mu-plugins folder and uploaded the s2-hacks.php file which contained the following:

<?php
add_filter('ws_plugin__s2member_mailchimp_merge_array', 'my_filter', 10, 2);
function my_filter($merge, $vars) {
	// $merge: Array of existing MERGE fields that s2Member passes by default.
	// $vars:  Array of defined variables in the scope/context of this Filter.

	$custom_merge = array(
		'ID'   => get_user_field('ID', $vars['user_id']),
		'Role'   => get_user_field('Role', $vars['user_id']),
		'Registration Date'   => get_user_field('Registration Date', $vars['user_id']),
		'Auto-EOT Date'   => get_user_field('Auto-EOT Date', $vars['user_id']),
		'Nick_Name' => get_user_field('Nick_Name', $vars['user_id']),
		'birth_date'   => get_user_field('birth_date', $vars['user_id']),
		'Street_Address' => get_user_field('Street_Address', $vars['user_id']),
		'Address_2nd'   => get_user_field('Address_2nd', $vars['user_id']),
		'City' => get_user_field('City', $vars['user_id']),
		'State'   => get_user_field('State', $vars['user_id']),
		'Zip' => get_user_field('Zip', $vars['user_id']),
		'Home_Phone'   => get_user_field('Home_Phone', $vars['user_id']),
		'Other_Phone' => get_user_field('Other_Phone', $vars['user_id']),
		'Spouse_Name'   => get_user_field('Spouse_Name', $vars['user_id']),
		'spouse_birth' => get_user_field('spouse_birth', $vars['user_id']),
		'Directory'   => get_user_field('Directory', $vars['user_id']),
	);

	return array_merge($merge, $custom_merge);
}

And I received the following email from Mailchimp after their confirmation email.

Yippee! You've got a new subscriber for your list Society of John Gaither 
Descendants.

Note: This is for your account named The Society of John Gaither Descendants

Email Address: mack.gaither@gmail.com
First Name: Angus
Last Name: Gaither
ID: 73
Username: 
Password: 
Display Name: 
Role: 0
Registration Date: 
First Payment Date: 
Last Payment Date: 
Auto-EOT Date: 
Paid Subscr. ID: 
Full Address: 
address_2nd: 
birth_date: 
city: 
directory: 
home_phone: 
nick_name: 
other_phone: 
spouse_birth: 
spouse_name: 
state: 
street_address: 
zip: 
I am a: 


Date: Aug 22, 2013 08:50 am
Signup IP: 96.247.193.33

Feels good to be loved. 

Cheers, 

The MailChimp Crew

And here is the Mailchimp log file from S2Member:

LOG ENTRY: Thu Aug 22nd, 2013 @ precisely 12:42 pm UTC
PHP v5.2.17 :: WordPress® v3.6 :: s2Member® v130816 :: s2Member® Pro v130816
Memory 28.60 MB :: Real Memory 28.75 MB :: Peak Memory 28.64 MB :: Real Peak Memory 28.75 MB
gaither.info/wp-login.php?action=register
User-Agent: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36
array (
  'function' => 'process_list_servers',
  'func_get_args' => 
  array (
    0 => 'subscriber',
    1 => '0',
    2 => 'mackgaither',
    3 => '5sWHZUnhn6H1',
    4 => 'mack.gaither@gmail.com',
    5 => 'Angus',
    6 => 'Gaither',
    7 => '96.247.193.33',
    8 => true,
    9 => true,
    10 => 73,
  ),
  'api_method' => 'listSubscribe',
  'list' => '7cc439dcce',
  'list_id' => '7cc439dcce',
  'merge_array' => 
  array (
    'MERGE1' => 'Angus',
    'MERGE2' => 'Gaither',
    'OPTIN_IP' => '96.247.193.33',
    'OPTIN_TIME' => '2013-08-22 12:42:53',
  ),
  'api_merge_array' => 
  array (
    'MERGE1' => 'Angus',
    'MERGE2' => 'Gaither',
    'OPTIN_IP' => '96.247.193.33',
    'OPTIN_TIME' => '2013-08-22 12:42:53',
    'ID' => 73,
    'Role' => false,
    'Registration Date' => false,
    'Auto-EOT Date' => false,
    'Nick_Name' => 'Mack',
    'birth_date' => '01/01/2011',
    'Street_Address' => '123 Main',
    'Address_2nd' => '',
    'City' => 'Benton',
    'State' => 'ID',
    'Zip' => '20202',
    'Home_Phone' => '202-202-2020',
    'Other_Phone' => '',
    'Spouse_Name' => 'Honey',
    'spouse_birth' => '01/01/1901',
    'Directory' => false,
  ),
  'api_email_type' => 'html',
  'api_double_optin' => true,
  'api_update_existing' => false,
  'api_replace_interests' => true,
  'api_send_welcome' => false,
  'api_response' => true,
  'api_success' => true,
  'api_properties' => 
  NC_MCAPI::__set_state(array(
     'version' => '1.3',
     'errorMessage' => '',
     'errorCode' => '',
     'apiUrl' => 
    array (
      'scheme' => 'http',
      'host' => 'api.mailchimp.com',
      'path' => '/1.3/',
      'query' => 'output=php',
      'prefix' => 'us5',
    ),
     'timeout' => 300,
     'chunkSize' => 8192,
     'api_key' => 'xxxxxxxx/api/key/sec',
     'secure' => true,
  )),
)

Hope this helps find the problem. Thanks again.

Posted: Wednesday Aug 28th, 2013 at 7:46 am #58780

Sorry, I just saw your reply. Thanks for the info.

It looks like the hack works, it’s sending the data for those fields. What doesn’t seem to be happening is MailChimp saving it. I wonder if they changed something on their side since the hack was written.

I don’t have a MailChiimp account to test this with. I’ll ask Jason about it and let you know when I hear back from him.

Posted: Wednesday Aug 28th, 2013 at 8:43 am #58795

Here’s what Jason said:

all of those MERGE vars need to actually exist in this MailChimp configuration too. By default, only MERGE1 and MERGE2 exist. If he’s adding new ones, those need to configured on the MailChimp side also, so they get saved by MailChimp.

Have you created those fields in MailChimp with those exact IDs/names?

Posted: Wednesday Aug 28th, 2013 at 9:26 am #58801

BTW, I thought I had posted this on the Customer Forum. I have paid for Pro.

That solved the problem for some of the fields. Before you replied to my first posting, I tried to match the field names in S2member with Mailchimp and ran into a problem. It appears that the Mailchimp field names are limited to 10 characters. In S2member I have default fields such as Last Payment Date and custom fields such as “spouse_name” that are longer than 10. Not knowing how to change the default length in mailchimp, or if it would recognize just the first 10 characters and be okay, I changed the field names in S2members. Unfortunately, doing that caused the data that had been entered by users to disappear. None of this mattered at that time because I didn’t know that I had to customize the program as you explained.

I tried changing the fields today in Mailchimp and it now works for those S2member fields that are 10 characters or less, but not for those longer field names. Is there a way to change the filed names in S2member without losing the data that has been entered? Thanks again for your help.

Posted: Thursday Aug 29th, 2013 at 7:49 am #58841

Thanks for the update.

If renaming the profile field is causing you trouble, what you could do is take care of it in the hack. The merge field names don’t have to match the s2Member profile field names. For example:

[hilite pre_code]
get_user_field('ID', $vars['user_id']),
'role' => get_user_field('Role', $vars['user_id']),
'reg_date' => get_user_field('Registration Date', $vars['user_id']),
'eot_date' => get_user_field('Auto-EOT Date', $vars['user_id']),
'nickname' => get_user_field('Nick_Name', $vars['user_id']),
'birthday' => get_user_field('birth_date', $vars['user_id']),
'street_1' => get_user_field('Street_Address', $vars['user_id']),
'street_2' => get_user_field('Address_2nd', $vars['user_id']),
'city' => get_user_field('City', $vars['user_id']),
'state' => get_user_field('State', $vars['user_id']),
'zip' => get_user_field('Zip', $vars['user_id']),
'phone_1' => get_user_field('Home_Phone', $vars['user_id']),
'phone_2' => get_user_field('Other_Phone', $vars['user_id']),
'spouse' => get_user_field('Spouse_Name', $vars['user_id']),
's_birth' => get_user_field('spouse_birth', $vars['user_id']),
'directory' => get_user_field('Directory', $vars['user_id']),
);

return array_merge($merge, $custom_merge);
}
[/hilite]

Of course, the array keys would match the merge field names you created in MailChimp.

I hope that helps. :)

Posted: Thursday Aug 29th, 2013 at 10:35 pm #58868

That did it. Thanks very much.

Posted: Thursday Aug 29th, 2013 at 11:18 pm #58872

Excellent! I’m glad that did it. Thank you for the update. :)

If it’s not too much to ask for, would you take a moment to rate s2Member and leave a comment over at wordpress.org? http://www.s2member.com/r/wp-rate/

A Facebook “like” would be great too! https://www.facebook.com/s2Member

Thanks in advance! :)

Viewing 8 replies - 1 through 8 (of 8 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.