Created
December 9, 2024 07:11
-
-
Save finalwebsites/a5f36bd0fc6af000b7c731d5e892c85d to your computer and use it in GitHub Desktop.
Contact Form 7 - Submit subscriber data to EmailOctopus
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Place this code into the functions.php file or your WordPress child theme | |
add_action('wpcf7_mail_sent', 'fw_wpcf7_subscribe_to_eo4wp' ); | |
function fw_wpcf7_subscribe_to_eo4wp( $contact_form ){ | |
// get form id | |
$form_id = $contact_form->id(); | |
// get submission data | |
$submission = WPCF7_Submission::get_instance(); | |
$posted_data = $submission->get_posted_data(); | |
if (!empty($posted_data['newsletter'])) { | |
$tag = 'newsletter'; | |
$data = array('tags' => $tag, 'FirstName' => $posted_data['your-name']); | |
$list = get_option('fweo_emailoctopus_list_id'); | |
$eo = new FWEO_EmailOctopus_integration(); | |
$eo->add_subscriber($posted_data['your-email'], $list, $data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
With this code snippet it is possible to send the name and email address of your CF7 form submission to EmailOctopus.
The condition is that the visitor has ticked a checkbox with the name "newsletter".
To get it working, you can use the following CF7 form. Note the similarity of the field names that are used here and also in the PHP code.
The function or action hook works together with the plugin EmailOctopus for WordPress.