Introduction
This article describes the CF7 / MC integration using the Plugin “MailChimp for WordPress” (MC4WP) by ibericode. There is another post covering the same subject via the plugin “Contact Form 7 Extension for Mailchimp”. However, MC4WP seems to be easier. It also provides a way to auto tag subscribers from CF7. Doing the same using the other plugin would require the Pro version.
Steps
- In MC4WP
- activate the connection using the API Key. The available Audience Lists will be listed.
- click the list, the Merge Fields will be displayed in a table.
- go to MC4WP >> Integrations, click ‘Contact Form 7’, and then under ‘Mailchimp Lists’ select the Lists where you want to connect with CF7.
- select other settings as required and save.
- In CF7, create the form:
- prefix the name of the field by ‘mc4wp-‘ and write all the letters of the field name in uppercase (see sample codes).
- verify that the names of your form fields match the names of the MailChimp fields, go to MC4WP >> MailChimp, click the name of your list, and verify the Tag of each field.
- add the [mc4wp_checkbox] tag in the form. The entered data is only sent to MailChimp if the users select this checkbox. If you don’t want to use the checkbox, add
<input type="hidden" name="mc4wp-subscribe" value="1" />to the form.
- When there are more than one List, to add subscribers from different forms to different Lists, add the following code in CF7 to specify the List id:
<input name="_mc4wp_lists[]" type="hidden" value="<list id>" />
- To auto tag subscribers, add a filter in functions.php. See sample code below
Sample Codes
<label> Your name
[text* mc4wp-NAME] </label>
<label> Your email
[email* mc4wp-EMAIL] </label>
<label> Your Phone
[tel mc4wp-PHONE] </label>
<label> Subject
[text* your-subject] </label>
<label> Your message (optional)
[textarea your-message] </label>
<input type="hidden" name="mc4wp-subscribe" value="1" />
[submit "Submit"]
// ^^^ MC4WP Add tags to MailChimp
add_filter( 'mc4wp_integration_contact-form-7_subscriber_data', function(MC4WP_MailChimp_Subscriber $subscriber, $cf7_form_id) {
if ($cf7_form_id == 2226) {
$subscriber->tags[] = 'cf7';
}
return $subscriber;
}, 10, 2);
