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.

Mailchimp Custom Profile Fields s2hacks.php

Home Forums Community Forum Mailchimp Custom Profile Fields s2hacks.php

This topic contains 3 replies, has 2 voices. Last updated by  Raam Dev 4 years, 2 months ago.

Topic Author Topic
Posted: Sunday Nov 4th, 2012 at 8:11 pm #30612

HI, I’m trying to get my custom profile fields into Mailchimp when a user registers using s2hacks.php.

I have 2 courses (course 1 = S2level2 and 3. course 2 = S2level 4) with their own lists in Mailchimp. I want to have the course start date on the members profile and I need to get it into Mailchimp.

I have 2 profile fields set up STDATE1 (limited to level 2 and 3) and STDATE2 (limited to level 4). These fields are uneditable – I will change them when enrolment for each course opens (enrolment is only open for 1 month, 4 times a year).

This is my s2hacks.php file so far:

\

<?php
add_filter("ws_plugin__s2member_mailchimp_double_optin", "__return_false");
add_filter("ws_plugin__s2member_mailchimp_send_welcome", "__return_true");
add_filter("ws_plugin__s2member_mailchimp_update_existing", "__return_true");

add_filter("ws_plugin__s2member_mailchimp_merge_array", "my_filter_mailchimpmerge", 10, 2);
function my_filter_mailchimpmerge($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. */

        $user_id = $vars["user_id"];
        // print_r($vars); // Lots of good stuff in this array.

        $user_level = get_user_field("s2member_access_level", $user_id);
        $user_cchstdate = get_user_field("STDATE1", $user_id);
	$user_advstdate = get_user_field("STDATE2", $user_id);

        $my_custom_merge_vars = array("LEVEL" => $user_level, "CCHSTDATE" => $user_cchstdate, "ADVSTDATE" => $user_advstdate);

        return array_merge($merge, $my_custom_merge_vars);
    }

?>

In Mailchimp list 1 has the merge field CCHSTDATE and list 2 has ADVSTDATE.

Will this work, or will it fail as both fields don’t exist in both lists. The courses have different start dates and can both be open for enrolment as the same time, so I need to be able to have 2 different fields.

Or, is there a better way to implement this? I thought about ccaps, but I’d like the start date to be visible on the member profile (I’m using BuddyPress). I also thought about custom variables via the Paypal button – but I’m using Tips&Tricks Affiliate plugin which uses cv1 for the affiliate ID and I’m not sure how I would implement this without breaking the affiliate system.

Thank you!!

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Monday Nov 5th, 2012 at 6:28 pm #30705
Raam Dev
Username: Raam
Staff Member

Hi Michelle,

I’m not sure what will happen if you try adding data to a MailChimp field that doesn’t exist on that list, but you can easily add code to the s2hacks.php file that simply checks the user’s level and then submits the merge data that corresponds to that list.

For example:

$user_level = get_user_field("s2member_access_level", $user_id);
        
if ($user_level == "1") {
	$user_cchstdate = get_user_field("STDATE1", $user_id);
	$my_custom_merge_vars = array("LEVEL" => $user_level, "CCHSTDATE" => $user_cchstdate);
}

if ($user_level == "2") {
	$user_advstdate = get_user_field("STDATE2", $user_id);
	$my_custom_merge_vars = array("LEVEL" => $user_level, "ADVSTDATE" => $user_advstdate);
}
Posted: Monday Nov 5th, 2012 at 8:20 pm #30713

Awesome, thanks Raam, I knew there was a better way to approach this – I just couldn’t see it! I’ll go test it now.

Posted: Tuesday Nov 6th, 2012 at 6:12 pm #30812
Raam Dev
Username: Raam
Staff Member

No problem. Let us know if you have any other questions. :)

Viewing 3 replies - 1 through 3 (of 3 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.