[Resolved] mc4wp (MailChimp for WordPress) user sync does not recognize date field
This thread is resolved. Here is a description of the problem and solution.
Problem:
mc4wp (MailChimp for WordPress) user sync does not recognize date field - How to get custom user date field value created using Types in specific date format in PHP
Solution:
Types offers the PHP function types_render_usermeta() to get the user custom field value.
I've added toolset custom user fields and need to add a date field that displays the end of a contact. I want to use mc4wp to sync the user fields to MailChimp so we can send an email two weeks before the end of contract date.
The form part of mc4wp recognizes all the custom user tooset fields and will update the Mailchimp contact correctly when submitting their form. The problem is the mc4wp does not add a new WordPress user. I using the toolset user form to add new registrations to the site. When submitted mc4wp adds the new registration to Mailchimp with the exception of the toolset date field.
I discovered ACF has the same problem however there is a snippet for their plugin that addresses the same problem. What i need to know is how to modify this snippet to accommodate Toolset user meta fields. I added an ACF custom field and this works but I would rather just use the toolset plugin. Any advice would be appreciated.
Thanks
// MailChimp field name: FOO
// ACF field name: bar
$subscriber->merge_fields['ENCONTRACT'] = get_field( 'contract_end_date', 'user_' . $user->ID );
// How can I modify the get_field portion so it looks up the toolset user fields? (this field also has to be formatted Y-m-d from the unix time stamp in the toolset date field)
Hello. Thank you for contacting the Toolset support.
Types offers the PHP function types_render_usermeta() to get the user custom field value.
Can you please try the following code:
add_filter( 'mc4wp_user_sync_subscriber_data', function( \MC4WP_MailChimp_Subscriber $subscriber, \WP_User $user ) {
$subscriber->merge_fields['ENCONTRACT'] = types_render_usermeta('field-slug',array('format'=>'Y-m-d','user_id'=>$user->ID));
// How can I modify the get_field portion so it looks up the toolset user fields? (this field also has to be formatted Y-m-d from the unix time stamp in the toolset date field)
return $subscriber;
}, 10, 2 );
Where:
- Please change field-slug with your original custom user field slug you created using Types.
Now I'm adding a checkbox and trying to use the same snippet.
How would I use the same snippet for a checkbox?
this is the code I'm trying for the checkbox
add_filter( 'mc4wp_user_sync_subscriber_data', function( \MC4WP_MailChimp_Subscriber $subscriber, \WP_User $user ) {
Here is the debug info.
Mailchimp User Sync: Debug user data
MC4WP_MailChimp_Subscriber Object
(
[email_address] => jill@jpearl.ca
[interests] => Array
(
[c3033aaca6] => Array
(
[0] => Seconded In
)