I’m using s2member with WordPress.
I set up a Fixed EOT(End of Term) for July 31st.
Here’s the coding I’m using..
<?php
$now = strtotime("now");
$fixed_time = strtotime("31 July 2013");
$days_until_fixed_time = round(($fixed_time - $now) / ($seconds_in_one_day = $86400));
?>
[s2member-Pro-PayPal-Form... tp="<?php echo $days_until_fixed_time; ?>" tt="D" ... /]
The code works fine as it is to set the EOT date as July 31, 2013.
But I need the year to auto generate according to the date.
If the user registers before July 31, EOT year should stay the current year.
If the user registers after July 31, EOT year should be set to the following year(2014).
And this will work without having to modify every year.
Hope this makes sense! Thank you for your help!
EDITED
would this work…
<?php
$now = strtotime("now");
$fixed_time = strtotime("31 July " . date("Y"));
if($now > $fixed_time)
$fixed_time = strtotime("+1 year", $fixed_time);
$days_until_fixed_time = round(($fixed_time - $now) / ($seconds_in_one_day = $86400));
?>
[s2member-Pro-PayPal-Form... tp="<?php echo $days_until_fixed_time; ?>" tt="D" ... /]
EDIT #2
have this code now..
<?php
$now = strtotime("now");
$mmdd = (int)date("M d");
$yyyy = (int)date("Y");
if ($mmdd <= 731)
$fixed_time = strtotime("31 July " . $yyyy);
else
$fixed_time = strtotime("31 July " . ($yyyy+1));
$days_until_fixed_time = round(($fixed_time - $now) / ($seconds_in_one_day = "86400"));
[s2member-Pro-PayPal-Form... tp="<?php echo $days_until_fixed_time; ?>" tt="D" ... /]
?>
problem is…
a) FIXED the EOT date comes out to be July 30th.
b) if the user registers AFTER the date, i get an error on the page saying the value needs to be 1 or greater..
“Invalid form configuration. Invalid “tp” attribute. The Trial Period. When provided, must be >= 1.”
still need help..
=============== SOLUTION ================
Figured out a working model! Thanks for everybody’s help!
<?php
$now = strtotime("now");
$fixed_time = strtotime("31 July " . date("Y"));
if($now > $fixed_time)
$fixed_time = strtotime("+1 year", $fixed_time);
$days_until_fixed_time = round(($fixed_time - $now) / (86400));
?>
[s2member-Pro-PayPal-Form... tp="<?php echo $days_until_fixed_time; ?>" tt="D" ... /]
This structure successfully implements July 31st as the EOT date. When the user registers before July 31st, the current year is set. If the user registers after July 31st, the next year is set.
You can just advance the year if we are after the
$fixed_time
UPDATE for new code:
Outputs:
That code does not work as intended. Casting a date to an int is a bad idea as you can see if produces 0, which means your if statement will ALWAYS be true;
My suggestion works fine look at this code that tests before the cutoff and after the cutoff. Your code is in the doStuff function with the
strtotime("now")
commented out so I can change the date strings:Output:
If you change this line to read the year dynamically:
that should work.
Assuming that you’ve converted $now into time() format:
31536000 = number of seconds in 1 year
if you’re doing this function a lot (in a loop?) strtotime is expensive