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.


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).


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.


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]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.”;

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):

$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>';
      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>';

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" /]


I answered my own question using the code from:


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:

just adding another vote for this.
ezPHP and other plugins are a huge security risk - and inconvenient because if you enter incorrect PHP code you could crash the whole site (worse if that happens because e.g. PHP 9.0 works differently than previous version for example - you then may not even know why your site is down and where to start looking for problems)

I also want to offer specific subscription / upgrade button only for users with XX days left.

There really should be an s2IfEOTTime till Demotion
e.g. s2IfEOT7D-0D
show this if time left is between 2years and 1 year.
or s2IfEOT2Y-1Y
days being most important - but as it’s time it would be convenient to have the standard H for hours, D for days, M for Months, and Y for years.
IT would be cool to have two dates available. I don’t need it but it should be no more work I guess to integrate it with a timespan - and that way it’s much more flexible.

Let’s push this again - would really be helpful. We have the new s2if conditional for gateway. An s2if days left smaller than X or in between would be really helpful.

(as well as changing the yellow Checkout Now button for the cancel or update form to an Cancel Now and and Update Now button - that way one can localise the button or adapt to to local regulations - it is really the biggest thing missing in giving better Usability to members.

Yes, I can understand the want for this.

First thing that comes to mind, is that as soon as a conditional like this were available, people would be expecting it to work in a way that it won’t, because many don’t understand that the EOT time for subscriptions is only set when they end. Active subscriptions don’t set an EOT time. https://s2member.com/kb-article/when-is-an-eot-time-set-for-each-user/

Having said that, if you want to help me test this before a release, please add this to a PHP file in your mu-plugins folder, and try it with an s2If and a test user account.

function current_user_days_to_eot_less_than($less_than) {
  $eot_time = get_user_field('s2member_auto_eot_time');
  if (empty($eot_time)) {
    return false;
  $now       = time();
  $time_diff = ($eot_time - $now);
  $days_left = round($time_diff / (60 * 60 * 24));
  return $days_left < $less_than;

[s2If current_user_days_to_eot_less_than(31)]Renew your membership[/s2If]

The s2If conditionals have to return a true or false, and have a descriptive name, and take only one parameter to keep them simple for most. Please tell me if you have any suggestions to improve the one I came up with there.


1 Like

Edit: had some error in my shortcode closing - seems to work great.

1 Like

Hi Felix,

Have you been using this? Noticed anything that needs adjusting, or is it still doing well?

You can also try this version:

function current_user_days_to_eot_less_than($days_limit) {
	$eot_time   = (int) get_user_field('s2member_auto_eot_time');
	$now        = time();
	$time_diff  = ($eot_time - $now);
	$days_left  = round($time_diff / (60 * 60 * 24));
	$days_limit = (int) $days_limit;
	return ($days_left < $days_limit);


1 Like

Hi Christian, yeah I’ve been using it - it works without problems.I just tried the second version which works too. As I have it within a
[s2If get_user_option(s2member_auto_eot_time)]

condition already - I don’t need the if empty line.


Thanks for the update! Glad it’s working well. I’ll add it to the next release then.

About the empty check, I’ll just keep it there, because it’s likely that not everyone will have the extra conditional as you did.


1 Like