• Resolved collectorcarnetwork

    (@collectorcarnetwork)


    Hello Danny,

    I’m using the pro version of MailChimp for WordPress in conjunction with Scroll Triggered Boxes. Both are great but to quote an old American candy ad, they’re “two great tastes that taste great together!”

    I’d like to know whether it is possible to prevent the box from appearing to (anonymous) visitors who have already taken the requested action. Can a persistent cookie (good for 1 year or so) be set when a visitor hits the submit button? Unless I’m doing something wrong, right now when a visitor submits they still get the box on subsequent pages until they click the “X” to close it. In case it helps, my blog is at https://blog.classiccars.com.

    Thanks for these 2 great plugins!

    https://www.ads-software.com/plugins/scroll-triggered-boxes/

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Danny van Kooten

    (@dvankooten)

    Hi there,

    Great idea and sure thing, this is totally possible. My MailChimp for WordPress plugin is quite extendible, with a few lines of code we can accomplish this.

    I will release an update of the Scroll Triggered Boxes plugin in order to make this work. After the update, I’ll reply here with a small code snippet you can add to your theme its style.css file to make this work. ??

    Thread Starter collectorcarnetwork

    (@collectorcarnetwork)

    Thanks Danny! Your plugin deserves 5 stars even without this functionality, so I just left a review. Looking forward to being able to keep the pop-up hidden for my subscribers.

    Happy holidays!

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hi there,

    Thank you for the amazingly kind review, much appreciated! ?? I just updated the plugin to version 1.1.4 which makes this possible.

    You can add the following code snippets to your theme its functions.php file to make this work. This file is usually located in /wp-content/themes/your-theme/functions.php.

    First, we have to set a cookie when someone subscribes using a MailChimp for WordPress sign-up form.

    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', 10, 4);

    Then, we have to tell the Scroll Triggered Boxes plugin to check for this cookie and if it is set not show the box.

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

    Here’s a complete code snippet you can add to your theme its functions.php file.

    Hope that helps! Let me know if you need any help.

    Thread Starter collectorcarnetwork

    (@collectorcarnetwork)

    Hi Danny,

    Thanks for the quick turnaround! I tried implementing the code in my functions file but I’m not setting a cookie as expected. STB does set a cookie when I click the “X” to close the box, however.

    I’m afraid I’m not a coder so I’m at a loss as to where I’m going wrong.

    I am seeing the following in my php error log, though:

    [23-Dec-2013 23:43:38 UTC] WordPress database error Table '[REDACTED].wp_mc4wp_log' doesn't exist for query INSERT INTOwp_mc4wp_log(email,list_ids,signup_method,signup_type,form_ID,comment_ID,merge_vars,datetime,url`) VALUES (‘[email protected]’,’aa25a565c2′,’form’,’sign-up-form’,’13231′,0,'{\”GROUPINGS\”:[{\”id\”:6033,\”groups\”:[\”Daily\”]}]}’,’2013-12-23 16:43:38′,’https://blog.classiccars.com/’) made by require(‘[PATH]\wp-blog-header.php’), require_once(‘[PATH]\wp-load.php’), require_once(‘[PATH]\wp-config.php’), require_once(‘[PATH]\wp-settings.php’), do_action(‘init’), call_user_func_array, MC4WP_Forms->submit, MC4WP_Forms->subscribe, do_action(‘mc4wp_subscribe_form’), call_user_func_array, MC4WP_Log->log_form_subscriber, mc4wp_log, W3_Db->insert, W3_DbCache->insert, W3_DbCallUnderlying->insert, W3_Db->insert, W3_DbProcessor->insert, W3_Db->default_insert, W3_Db->query, W3_DbProcessor->query, W3_Db->default_query
    `

    Thread Starter collectorcarnetwork

    (@collectorcarnetwork)

    OK, I got it working by changing the first add_action call to mention the new function:

    add_action('mc4wp_after_subscribe', 'my_prefix_set_mailchimp_cookie', 10, 4);

    Now my cookies are being set properly. Hooray!

    Thanks for an awesome plugin that only keeps on getting better!!!

    Plugin Author Danny van Kooten

    (@dvankooten)

    Oops – my bad. Not sure how I could’ve missed that, glad you figured it out yourself.

    On a side note, which MC for WP version are you on? Seems like a table required for the logging (the Reports) isn’t working. This was fixed in version 1.97 and the latest version is 1.98.2. ?? If you’re not seeing updates in your admin panel, please let me know by email. I’d be happy to help out!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Hiding the box for subscribers?’ is closed to new replies.