Hi @3cats,
Are you using the function in the article? That function shows an example of how to add the first name.
I can customize the function for you to get the first name and last name. This is what you’ll need to provide me:
- Your MailChimp
MERGE
tag for first name (usually FNAME
)
- Your MailChimp
MERGE
tag for last name (usually LNAME
)
- Your CF7 first name field
- Your CF7 last name field
I believe that Contact Form 7 usually uses one field for name (your-name
). You’ll need to set it up to use two separate fields (so something like first-name
and last-name
).
Let me know.
Cheers,
Kevin.
Thread Starter
3cats
(@3cats)
Hi Kevin, thanks so much for helping me!
1. MailChimp merge tag for first name is FNAME
2. MailChimp merge tag for last name is LNAME
3. CF7 first name field is [text* your-firstname]
4. CF7 last name field is [text* your-lastname]
It’s really to see how you write the function to add mores variables to it. I just don’t know how to combine them.
Thanks again!
Hi @3cats,
This is what your function should look like (delete your current one if you already copied it).
/*
* Populate the 'Name' field in the MailChimp Mailing list from the 'your-name' field in Contact Form 7
*
* @since 6.0.2.1
*
* @param array | $merge_variables | An array of variables we're sending to MailChimp
* @param array | $cf7_variables | An array of variables we received from the CF7 form submission
* @return array| $merge_variables | An array of variables we're sending to MailChimp, hopefully with CF7 variables added
*/
function additional_contact_form_7_data( $merge_variables, $cf7_variables ) {
// Check our $cf7_variables array for 'your-firstname'
if ( isset( $cf7_variables['your-firstname'] ) ) {
// Filter first name and add it to our MailChimp merge variables array
$merge_variables['FNAME'] = filter_var( $cf7_variables['your-firstname'], FILTER_SANITIZE_STRING );
}
// Check our $cf7_variables array for 'your-firstname'
if ( isset( $cf7_variables['your-lastname'] ) ) {
// Filter first name and add it to our MailChimp merge variables array
$merge_variables['LNAME'] = filter_var( $cf7_variables['your-lastname'], FILTER_SANITIZE_STRING );
}
return $merge_variables;
}
add_filter( 'yikes-mailchimp-contact-form-7', 'additional_contact_form_7_data', 10, 2 );
Let me know if that’s working for you! I can test help run a test subscription if you send over a URL to your site.
Cheers,
Kevin.
Thread Starter
3cats
(@3cats)
Again many thanks! I’ll let you know once it’s implemented.
Best,