Home / Archive / MemberPress: Free-Views-Left Counter
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Free-Views-Left Counter

This code will add the counter notification showing users how many free views they have left before the paywall kicks in.

Code Preview
php
<?php
function mepr_display_cookie() {
  if ( isset( $_COOKIE['mp3pi141592pw'] ) && ! empty( $_COOKIE['mp3pi141592pw'] ) ) {
    $cookie = $_COOKIE['mp3pi141592pw'];
    $mepr_options = MeprOptions::fetch();
    $num_views    = base64_decode( $cookie );
    if ( $num_views < $mepr_options->paywall_num_free_views ) {
      $free_views = $mepr_options->paywall_num_free_views - $num_views;
      echo 'You have ' . $free_views . ' left!';
    }
  }
}
add_action( 'init', 'mepr_display_cookie' );

Comments

Add a Comment