Hi there,
Yes, you can definitely do this if you’re using my other plugin; MailChimp for WordPress. We would need to know the box ID for this though, you can find it in the URL when editing a box (post).
Once you know it, add the following piece of code to your theme its functions.php
file.
function myprefix_set_mc_cookie( $email, $merge_vars, 0, $result ) {
$box_id = YOUR_BOX_ID_HERE;
if( $result == true ) {
setcookie( "stb_box_{$box_id}", true, strtotime( "+1 year" ), '/' );
}
}
add_action( 'mc4wp_after_subscribe', 'myprefix_set_mc_cookie', 10, 4 );
You will need to change the snippet so YOUR_BOX_ID_HERE
becomes the numeral ID of the box you would like to hide once a user sign-ups through a MailChimp for WordPress sign-up form.
Hope that makes sense, good luck. 🙂
danny,
i actually looked through the support and found this code:
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);
add_action(‘mc4wp_after_subscribe’, ‘my_prefix_set_mailchimp_cookie’, 10, 4);
how does this differ from yours? And would it work? i don’t see any box_id field on the one i found.
Hi there,
Ah, yes. That’s another way to do it without needing the box ID.
Here is the cleaned-up version of that code.
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);
Hope that helps!