Viewing 9 replies - 1 through 9 (of 9 total)
  • Hey there, @silviossilvestrou!

    While it’s possible to integrate with MailChimp using HappyForms PHP hooks, there’s no visual way to do it yet, we’re sorry! That’s already on our roadmap though, so stay tuned!

    If you’re in a hurry instead, and would like to know more about manually integrating with MailChimp, just let us know and we’ll share some useful pointers.

    Let us know what you think!

    Thread Starter silviossilvestrou

    (@silviossilvestrou)

    Hi,
    yes, please!
    if are not difficult, I would like to know!
    Thanks

    Got it, @silviossilvestrou!

    Before sharing actual pointers, could you share some details about what kind of integration you’d like to pull off?

    Let us know!

    Thread Starter silviossilvestrou

    (@silviossilvestrou)

    Hi @thethemefoundry !

    BasicallyI, would like if I could connect the HappyForms with Mailchimp-(Lists)!

    Thanks!

    Thanks, @silviossilvestrou!

    Just to be clear, does that mean you’d like to subscribe an email address submitted through the form to your MailChimp list automatically?

    Let us know if that’s what you’re after.

    Thread Starter silviossilvestrou

    (@silviossilvestrou)

    Hello @thethemefoundry,

    Yes , that corect!!

    i am using Elementor forms (newsletter), and they are easyly conect with my Mailchimp lists!

    Thanks

    Got it, @silviossilvestrou!

    Consider a much easier integration method is already planned for HappyForms. In the meanwhile, here’s how you can hook up a connection yourself using PHP.

    Before starting:

    1. Grab your MailChimp API key.
    2. Grab your datacenter ID: to do that, look at your URL in your MailChimp dashboard. My URL looks like: https://us18.admin.mailchimp.com and my datacenter ID is us18.
    3. Grab your list ID.
    4. In your HappyForms edit form screen, grab the labels (the value of your Title part field) of your first name, last name and email parts. We’ll use those labels to identify the parts whose values will actually end up in your MailChimp subscriber data.

    Adding the integration:

    1. Open your theme functions.php file, and pop in this snippet replacing with your actual IDs, key values and labels:

    $datacenter = '[your datacenter ID]';
    $api_key = '[your api key]';
    $list_id = '[your list ID]';
    $first_name_label = '[your first name part label]';
    $last_name_label = '[your last name part label]';
    $email_label = '[your email part label]';

    2. Pop in this snippet, which handles submission to MailChimp:

    function child_theme_mailchimp_subscribe( $first_name, $last_name, $email ) {
    	global $datacenter, $api_key, $list_id;
    
    	$api_url = "https://{$datacenter}.api.mailchimp.com/3.0/lists/{$list_id}/members/";
    	$data = array(
    		'email_address' => $email,
    		'status' => 'subscribed',
    		'merge_fields' => array(
    			'FNAME' => $first_name,
    			'LNAME' => $last_name,
    		),
    	);
    
    	$args = array(
    		'headers' => array(
    			'Content-Type' => 'application/json; charset=utf-8',
    			'Authorization' => 'Basic ' . base64_encode( "any:{$api_key}" ),
    		),
    		'body' => json_encode( $data ),
    	);
    
    	wp_remote_post( $api_url, $args );
    }

    3. Finally pop in this snippet, which hooks HappyForms to the submission function:

    function child_theme_submission_success( $submission, $form, $message ) {
    	global $first_name_label, $last_name_label, $email_label;
    
    	$parts = wp_list_pluck( $form['parts'], 'label', 'id' );
    	$first_name = '';
    	$last_name = '';
    	$email = '';
    
    	foreach( $parts as $id => $label ) {
    		switch( $label ) {
    			case $first_name_label:
    				$first_name = $submission[$id];
    				break;
    			case $last_name_label:
    				$last_name = $submission[$id];
    				break;
    			case $email_label:
    				$email = $submission[$id];
    				break;
    		}
    	}
    
    	child_theme_mailchimp_subscribe( $first_name, $last_name, $email );
    }
    
    add_action( 'happyforms_submission_success', 'child_theme_submission_success', 20, 3 );

    That’s a bit verbose, but hopefully not too complex! Let us know how that goes. ??

    Thread Starter silviossilvestrou

    (@silviossilvestrou)

    Hi @thethemefoundry

    Thanks for the direct response!
    i will give the try, otherwise I will wait for you are new update!

    Thank you ??

    newtowordpressmatters

    (@newtowordpressmatters)

    Hi @thethemefoundry
    I’m following along the post and I’m not sure of this feature has been implemented or not.
    I used the snippets you suggested and I get 500 error code (Internal server error)

    I trust the code you wrote is good. Any idea what might be the reason and hpw to fix it?

    Thank you

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Integrations??’ is closed to new replies.