Skip Navigation

[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.

You can find the proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/mc4wp-mailchimp-for-wordpress-user-sync-does-not-recognize-date-field/#post-1870401

Relevant Documentation:
- https://toolset.com/documentation/customizing-sites-using-php/functions/#date

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by jayesonE 4 years, 4 months ago.

Assisted by: Minesh.

Author
Posts
#1869623

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

//mc4wp_user_sync_subscriber_data
add_filter( 'mc4wp_user_sync_subscriber_data', function( \MC4WP_MailChimp_Subscriber $subscriber, \WP_User $user ) {

// 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)

return $subscriber;
}, 10, 2 );

#1870401

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

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.

More info:
=> https://toolset.com/documentation/customizing-sites-using-php/functions/#date

#1870667

My issue is resolved now. Thank you! I now have to add some dropdown fields so I'm hoping I can use the same function.

#1871235

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 ) {

$subscriber->interests[c3033aaca6][] = types_render_usermeta( 'position-type', array( "user_id" => $user->ID ) );

return $subscriber;
}, 10, 2 );

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
)

)

[merge_fields] => Array
(
[FNAME] => Jillian
[LNAME] => Hills
[NAME] => jills
[COUNSELPOS] => Counsel
[MSTARTDATE] => 2020-12-17
[CNTRACTEND] => 2020-12-31
)

[status] =>
[email_type] =>
[ip_signup] =>
[language] =>
[vip] =>
[tags] =>
)

New threads created by Minesh and linked to this one are listed below:

https://toolset.com/forums/topic/split-mc4wp-mailchimp-for-wordpress-how-to-access-checkbox-value-using-php/