WordPress.org

Ready to get started?Download WordPress

Forums

Scroll Triggered Boxes
[resolved] Hide box after signup (3 posts)

  1. viensia
    Member
    Posted 5 months ago #

    Hi Danny,

    Wonderful plugin!! Is there a way to have the box automatically close after someone submits a request on it? I am using contact 7 form and it would be great for it to close upon user input. Also, is there a code to keep it from opening again after input? Like the one that you have for mail-chimp?

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

  2. Danny van Kooten
    Member
    Plugin Author

    Posted 5 months ago #

    Hi there,

    Sure thing but it depends entirely on the thing you're trying to integrate with. You can filter the box rules and keep the box hidden if a certain cookie is set so if you can set a cookie upon submitting a form, you're good to go.

    Here is the example code for MailChimp for WordPress.

    // 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);

    I am thinking of adding a few integrations to the plugin to handle this kind of stuff automatically for some of the more popular plugins (like MailChimp for WordPress and Contact Form 7) so stay tuned. :-)

  3. Danny van Kooten
    Member
    Plugin Author

    Posted 4 months ago #

    The above code can be simplified to the following snippet if you're using MailChimp for WP version 1.5.4 or higher.

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.