WordPress.org

Ready to get started?Download WordPress

Forums

Scroll Triggered Boxes
[resolved] Box not closing after Mailchimp signup (3 posts)

  1. Caged
    Member
    Posted 5 months ago #

    I want the box to close after a Mailchimp signup so i used the following script from http://wordpress.org/support/topic/hide-box-after-signup but somehow this solution does not seem to work for me.

    This is the code exact code pasted into my child theme's functions.php:

    // copy paste the following functions anywhere in your theme its functions.php file
    
    function my_prefix_set_mailchimp_cookie($email, $merge_vars, $form_id, $result) {
    	if($result == true) {
    		setcookie("mc4wp_subscribed", $email, time() + 31556926, '/');
    	}
    }
    
    add_action('mc4wp_after_subscribe', 'my_prefix_set_mailchimp_cookie', 10, 4);
    
    function my_prefix_show_stb_box($matched, $box_id) {
    
    	if(isset($_COOKIE['mc4wp_subscribed'])) {
    		return false;
    	}
    
    	return $matched;
    }
    
    add_action('stb_show_box', 'my_prefix_show_stb_box', 10, 2);

    Even though i pasted this exact code in the child theme's functions.php the cookie does not get set so the box still appears.

    Are there any required changes to the code before i can use it?

    Love this plugin BTW, i'm sure there's a solution for this. :)

    https://wordpress.org/plugins/scroll-triggered-boxes/

  2. Danny van Kooten
    Member
    Plugin Author

    Posted 5 months ago #

    Hi there,

    Are you using the MailChimp for WordPress? The code posted above will only work if using that plugin.

    Actually, by now the code can be simplified to the following.

    function my_prefix_show_stb_box($matched, $box_id) {
    
    	if(isset($_COOKIE['mc4wp_email'])) {
    		return false;
    	}
    
    	return $matched;
    }
    
    add_action('stb_show_box', 'my_prefix_show_stb_box', 10, 2);

    If you're using another way to handle your MailChimp sign-ups it will be quite hard to accomplish the same thing.

    Hope that helps, let me know if it doesn’t! :-)

  3. Caged
    Member
    Posted 5 months ago #

    At the moment of writing my opening post i was not using the MailChimp for WordPress plugin. That's why the code didn't work of course.

    Using both plugins now and it works great!

Reply

You must log in to post.

About this Plugin

About this Topic