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.

Registration Wont Update Mailchimp Merge Tags

Home Forums Community Forum Registration Wont Update Mailchimp Merge Tags

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

Topic Author Topic
Posted: Friday Mar 23rd, 2012 at 9:03 am #8905

Okay, so here’s what I’m trying to do

1) user registers on my registration page, and fill out 2 custom fields (budget, weight goal)

2) i created a file /wp-content/mu-plugins/s2hacks.php that is supposed to update mailchimp upon registration

<?php
add_filter("ws_plugin__s2member_mailchimp_merge_array", "my_filter");
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. */

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

        $budget = get_user_field("s2member_budget", $user_id);
        $wtgoal = get_user_field("s2member_wtgoal", $user_id);

        $my_custom_merge_vars = array("BUDGET" => $budget, "WTGOAL" => $wtgoal);

        return array_merge($merge, $my_custom_merge_vars);
    }
?>

3) mailchimp is not receiving these additional 2 fields both named “BUDGET” and “WTGOAL”

4) s2member IS receiving my input data as evidence by this function

<?php 		
$s2 = get_user_option('wp_s2member_custom_fields', $user_id); 
var_dump($s2);			
?>

whose output is

array(2) { ["wtgoal"]=> string(6) "LESS25" ["budget"]=> string(7) "300PLUS" }

Can you please tell me what I’m missing in the s2-hacks.php file?

List Of Topic Replies

Viewing 25 replies - 1 through 25 (of 36 total)
Author Replies
Author Replies
Posted: Friday Mar 23rd, 2012 at 9:00 pm #8981

Hi Andrew.

Have you created the “BUDGET” and “WTGOAL” merge fields in MailChimp?

Posted: Saturday Mar 24th, 2012 at 8:27 am #9009

These fields exist in mailchimp.

Posted: Saturday Mar 24th, 2012 at 4:17 pm #9016

Got it.

Just to check if the arrays are what they’re supposed to be, after the line

[hilite pre_code]
$my_custom_merge_vars = array("BUDGET" => $budget, "WTGOAL" => $wtgoal);
[/hilite]

could you add these as a test?

[hilite pre_code]
echo '<'.'pre>';
print_r($my_custom_merge_vars);
print_r($merge);
echo '

';
[/hilite]
*Had to split the pre tag cause it was getting parsed here in the post :P

Posted: Saturday Mar 24th, 2012 at 5:43 pm #9017

I added that and registered on the site but I’m not seeing where this information should be printed.

Posted: Sunday Mar 25th, 2012 at 2:06 am #9026

Hmm… I think I see what the problem is with the hack. It’s missing the priority and number of arguments in the [hilite mono]add_filter[/hilite] function call. http://codex.wordpress.org/Function_Reference/add_filter

Try this, please:

[hilite pre_code]
$budget, 'WTGOAL' => $wtgoal));
}
?>
[/hilite]
Posted: Sunday Mar 25th, 2012 at 11:03 am #9042

Dang, just updated it with the code above and still nothing.

Posted: Sunday Mar 25th, 2012 at 7:44 pm #9070

Hmm… I think [hilite mono]get_user_field[/hilite] is being used wrongly, cause it doesn’t have access to the specific fields like that, you have to get the whole array of custom fields getting [hilite mono]s2member_custom_fields[/hilite].

How about this?

[hilite pre_code]
$cfields['budget'], 'WTGOAL' => $cfields['wtgoal']));
}
?>
[/hilite]
Posted: Monday Mar 26th, 2012 at 8:17 am #9104

Success!

It worked.

Do you know why it wasn’t working previously? Was the original code sample I used from an older version of the plugin? I’m just trying to learn more about how the plugin is built so I can continue to bolt on the features I need.

Posted: Monday Mar 26th, 2012 at 8:53 am #9105
cassel
Username: cassel

Only somewhat related to this but i like what i see. I wonder if this kind of coding could be used to automatically fill merge tags in MC with the date of registration/purchase of a certain product (based on ccaps)? If so (and if it is not already included in the next major release) i might look into that.

  • This reply was modified 4 years, 9 months ago by  cassel.
Posted: Monday Mar 26th, 2012 at 9:04 am #9107

Success!

It worked.

Do you know why it wasn’t working previously? Was the original code sample I used from an older version of the plugin? I’m just trying to learn more about how the plugin is built so I can continue to bolt on the features I need.

Great! :)

Right, seems to have been an outdated script. I guess the function changed since then, I just noticed the mistake yesterday when I reviewed its documentation again after a long time.

Only somewhat related to this but i like what i see. I wonder if this kind of coding could be used to automatically fill merge tags in MC with the date of registration/purchase of a certain product (based on ccaps)? If so (and if it is not already included in the next major release) i might look into that.

Yes, you can adapt the hack to store other values, like registration dates.
[hilite path]Dashboard -› s2Member® -› API / Scripting -› Content Dripping[/hilite]
http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field%28%29

Posted: Monday Mar 26th, 2012 at 9:04 am #9108

Perfect, thanks so much for the help!

Posted: Monday Mar 26th, 2012 at 9:13 am #9110
cassel
Username: cassel

Yes, you can adapt the hack to store other values, like registration dates.
Dashboard -› s2Member® -› API / Scripting -› Content Dripping
http://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field%28%29

Any info whether it is included in the next release before i get into coding?

Posted: Monday Mar 26th, 2012 at 9:20 am #9111

Perfect, thanks so much for the help!

You’re welcome! I’m glad I could help you. :)

Any info whether it is included in the next release before i get into coding?

Heh, there’s a good chance. There will be a big improvement for this, but I’m not sure if it’ll include payment times, so you may still need to use a hack.

Anyway, this hack is quite simple, so it won’t take you too long to implement now, or update later. ;)

Posted: Monday Mar 26th, 2012 at 9:24 am #9112
cassel
Username: cassel

Heh, there’s a good chance. There will be a big improvement for this, but I’m not sure if it’ll include payment times, so you may still need to use a hack.
Anyway, this hack is quite simple, so it won’t take you too long to implement now, or update later. ;)

Great to know. I might just get to learn more coding, even if just for the “fun” of it! :)
Thanks Andrew for the code!

Posted: Monday Mar 26th, 2012 at 9:39 am #9113

:)

Posted: Monday Mar 26th, 2012 at 2:04 pm #9127

As an add-on to this question, can you help me, here’s what I’m trying to do.

1) user registers for the site by replicating the signup form

2) user details are sent to mailchimp (as completed in the above function)

3) i then take the user to a survey where they have to fill out 5-6 additional questions

4) user submits their information, its stored in s2member_custom_fields

5) the information is then sent to mailchimp to sync

— Basically I just need to be able to run the mailchimp_merge_array through some sort of PHP call so I can sync the data in the wordpress database with what Mailchimp has

Posted: Monday Mar 26th, 2012 at 2:36 pm #9131

You may want to try using this method, which is the one that does the job during registration, only you’d call it at some other time: [hilite mono]c_ws_plugin__s2member_list_servers::process_list_servers[/hilite]
http://www.s2member.com/codex/stable/s2member/list_servers/c_ws_plugin__s2member_list_servers/#src_doc_process_list_servers%28%29

Posted: Monday Mar 26th, 2012 at 4:11 pm #9137

Cristian, can you explain how to use this function?

Here is what I have

// get the user fields and then update them with the data sent to this page
$custom_fields = get_user_option("s2member_custom_fields");
$custom_fields = array(
'AGE' => $age,
'BUDGET' => $budget,
'WTGOAL' => $wtgoal,
'HEALTH' => $health,
'BODY' => $body,
'MEALTYPE' => $mealtype,
'EXERCISE' => $exercise,
'GENDER' => $gender,
'FIRST_NAME' => $first_name
);
update_user_option($user_id, 's2member_custom_fields', $custom_fields);
// update this user based on their email and userid
process_list_servers($email, $user_id);

and then in s2-hacks.php i have this

<?php
add_filter('ws_plugin__s2member_mailchimp_merge_array', 'mailchimp_merge', 10, 2);
function mailchimp_merge($merge, $vars)
{
	$cfields = get_user_option('wp_s2member_custom_fields', $vars['user_id']);

	return array_merge($merge, array('BUDGET' => $cfields['budget'], 'WTGOAL' => $cfields['wtgoal'], 'AGE' => $cfields['age'], 'HEALTH' => $cfields['health_conditions'], 'BODY' => $cfields['body'], 'MEALTYPE' => $cfields['meal_type'], 'EXERCISE' => $cfields['exercise'], 'GENDER' => $cfields['gender'], 'FNAME' => $cfields['first_name']));
}
?>

When I check for the user details in Mailchimp its not updating the.m

  • This reply was modified 4 years, 9 months ago by  andrew wise.
Posted: Tuesday Mar 27th, 2012 at 2:02 am #9171

Sorry, I can’t help with that. :/
s2Member® » Support Policy » Fine Lines

If you need a developer’s help, you could find good freelancers in sites like oDesk.com, eLance.com or jobs.wordpress.net.

I hope that helps. :)

Posted: Tuesday Mar 27th, 2012 at 7:15 am #9201

Cristian, thanks for the help well I guess my question is for this function to work properly can you show me an example request?

When I ran it above, I only had 2 parameters included, but I’m assuming I need to have all of the parameters included to have this function initiate itself?

Posted: Tuesday Mar 27th, 2012 at 3:12 pm #9268
[hilite pre_code]
$cfields = get_user_option('wp_s2member_custom_fields', $vars['user_id']);
[/hilite]

will give you all the custom fields that have a value for the user, not just budget and wtgoal. You can add more of those to the array to be merged. Is that what you meant?

Posted: Tuesday Mar 27th, 2012 at 3:15 pm #9271

Can you show me how to use this function?

process_list_servers($email, $user_id);

i’ve got everything filled out except the password, but its not working, so i must be missing something

process_list_servers('subscriber', '0', $login, '', $email, $first_name, '', $ip, 'true', 'false', $user_id);
Posted: Thursday Mar 29th, 2012 at 5:08 am #9437

I asked Jason about using [hilite mono]c_ws_plugin__s2member_list_servers::process_list_servers[/hilite] and if all arguments were required to make it work, including password. Here’s his reply:

Yes, a site owner could certainly use this through a hack if they like.

All arguments are required, but you’re right, the plain text password is nearly impossible. That can be spoofed with something like “xxx”, just so it has a value. s2Member only passes that along to AWeber in a few special cases, and it’s NOT anything real important. I’ts fine 99.9% of the time to just spoof that.

If a site owner uses this hack…
[hilite pre_code]

[/hilite]
Only then will s2Member actually need the plain text password. In all other cases, just spoof it with the encrypted version, or just use “xxx”.

Posted: Thursday Mar 29th, 2012 at 11:22 am #9464

Thanks for the help, I think I’m almost there.

To run this function, do I have to add in a filter? I’m trying to just call it on a random page on my site, but its throwing an error (which i cant see because my shared server does not show php erros).

Here is what I’m calling, and all variables have content.

process_list_servers('subscriber', '0', $login, 'xxx', $email, $first_name, 'xxx', $ip, 'true', 'false', $user_id);
Posted: Thursday Mar 29th, 2012 at 4:32 pm #9488
Viewing 25 replies - 1 through 25 (of 36 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.