ericakfranz
1/13/2015 - 7:08 PM

limit-optin-view.php

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

}