Display content based on time until EOT

If there a way using s2If to display content based on the time until EOT. For example, 3 months before EOT display something, then a month before EOT display something else. Thanks.

1 Like

Great question.

No, not with s2If. You could do it with PHP conditionals, though…

Take a look at these:
WP admin > s2Member > API / Scripting > Advanced PHP Conditionals
WP admin > s2Member > API / Scripting > Content Dripping

Also: https://www.s2member.com/codex/stable/s2member/api_functions/package-functions/#src_doc_get_user_field()

$s2member_auto_eot_time = get_user_field ("s2member_auto_eot_time"); # Auto EOT-Time for the current User (when applicable).

And:

I hope that helps. :slight_smile:

I’ll go through that and I’ll probably figure it out, but can I suggest added that functionality to s2If? Thanks.

Sure. Made a note about it with your vote.

:slight_smile:

So I found this code that someone else wrote:

I then inserted a version of it into [php][/php] tags from ezPHP, although I did so within an existing s2If function I already had in the widget. Not sure if that works. In any case it really messed up my site. A took a closer look at how to use the shortcodes and rewrote it, but it still messed up things. What am I doing wrong here?

    [php]$your_date = ($s2member_auto_eot_time = get_user_field (“s2member_auto_eot_time”));
    $now = time();
    $datediff = ($your_date - $now);
    $timeleft = round($datediff / (60 * 60 * 24));
    if($timeleft >=30 && $timeleft <=90)[/php]
    <p></p>You can now renew your membership for next year. Go to the <a href="#">Membership Renewal</a> page to renew now. Thank you.
    [php]endif;[/php]
    [php]if($timeleft >=0 && $timeleft <=30)[/php]
    <p></p>In order to insure uninterrupted membership you need to renew your membership by the end of the calendar year. To do so, go to the <a href="#">Membership Renewal</a> page to renew now. Thank you.”;
    [php]endif;[/php]

Admittedly that seems really awkward. Originally I enclosed all the PHP into a single set of PHP shortcodes and used echo to output the text, but that gave me the same results, and after reviewing the examples on:

The above code seemed to be correct, if awkward. Yet, it’s clearly not as the display of everything on the page got messed up. Would removing it from the S2If statement and moving that to the PHP code help?

I refactored your code a bit (haven’t tested it much):

[php]
$eot_time = get_user_field('s2member_auto_eot_time');
if (!empty($eot_time)) {
  $now       = time();
  $time_diff = ($eot_time - $now);
  $days_left = round($time_diff / (60 * 60 * 24));

  if ($days_left < 91) {
    if ($days_left > 30)
      echo '<p>You can now renew your membership for next year. Go to the <a href="#">Membership Renewal</a> page to renew now. Thank you.</p>';
    else
      echo '<p>In order to insure uninterrupted membership you need to renew your membership by the end of the calendar year. To do so, go to the <a href="#">Membership Renewal</a> page to renew now. Thank you.</p>';
  }
}
[/php]

I hope that helps getting you closer! :slight_smile:

That worked! Thank you. Another question. I want to move some of what I have in an S2If statement into this code (because I want to check if the EOT is over a certain amount of time. How would I translate the following S2Eot shortcode into PHP?:

[s2Eot mode="fixed" date_format="M jS, Y" /]

Thanks

I answered my own question using the code from:

https://wordpress.org/support/topic/s2get-shortcode-to-display-end-of-term-account-expiration-date/

Just to be clear, there can never be an EOT time in the past, correct? My code wouldn’t deal with that possibility, so I want to make sure. Presumably when the EOT time is reached, the account is switched to level 0 and the EOT time is erased. Is that correct?

May I also chime in on this thread…I am also wanting to display a Paypal button on a page based on EOT. I have users with 12 month (1 year memberships) and would like the renewal paypal button to be unavailable for existing logged in members unless they have less than 31 days to go before renewal.

Will the above code also work for me?

It would be good if this was included into s2members directly.

1 Like

Correct. :slight_smile:

Yes, sounds like it would.

Added your vote for it. :slight_smile: