Last active
August 29, 2015 14:03
-
-
Save aaroneaton/afc887d53ffbc65b308f to your computer and use it in GitHub Desktop.
Limits the number of times an optin can be viewed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'optinmonster_output', 'limit_views' ); | |
function limit_views ( $optins ) { | |
// Replace this with your optin slug | |
$optin_slug = 'yf3rluqqcj-lightbox'; | |
// Replace this with the number of views | |
$view_limit = 100; | |
// Set the specified optin to false if limit has been reached | |
if ( isset( $optins[$optin_slug] ) ) { | |
$args = array( | |
'name' => $optin_slug, | |
'post_type' => 'optin', | |
'post_status' => 'publish', | |
'numberposts' => 1, | |
); | |
$posts = get_posts( $args ); | |
$target = $posts[0]; | |
// If you want to limit by conversions, change 'om_counter' to 'om_conversions' | |
$count = get_post_meta( $target->ID, 'om_counter', true ); | |
if ( (int) $count > (int) $view_limit ) { | |
$optins[$optin_slug] = false; | |
} | |
} | |
return $optins; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment