Hi Raam, thanks for your reply. From your explanation, I was on the right track. These steps produce a date-based EOT without enabling PHP execution (in PayPal button shortcodes). If you see anything alarming or potentially dangerous with this setup, please say so.
First, I created the s2-hacks.php file as outlined here and wrote this custom function, attached to the ws_plugin__s2member_before_sc_paypal_button action.
<?php
add_action("ws_plugin__s2member_before_sc_paypal_button", "s2_hacks_eot_by_date");
function s2_hacks_eot_by_date($vars = array())
{
if ($vars["attr"]["expire"] && $vars["attr"]["cutoff"])
{
$expire = strtotime($vars["attr"]["expire"] . "+1 day"); // Include all of the last day
$cutoff = strtotime($vars["attr"]["cutoff"] . "+1 day"); // Include all of the last day
$now = time();
if($now > $cutoff) {
$expire = strtotime(date("Y-m-d", $expire) . "+1 year"); // Add one year if after cutoff
}
$timeleft = $expire-$now;
$daysleft = round((($timeleft/24)/60)/60) + 1; // Add one day to include the last day
$vars["attr"]["rp"] = $daysleft; // Set the number of days
$vars["attr"]["rt"] = "D"; // Set the rate term to days
$vars["attr"]["custom"] .= "|" . date("Y-m-d", $expire); // Append computed EOT to the custom field
unset($vars["attr"]["expire"]);
unset($vars["attr"]["cutoff"]);
}
return;
}
?>
Next, I wrote the PayPal button shortcode, adding values for expiration and a cut off date.
[s2Member-PayPal-Button level="1" ccaps="" desc="Individual Member / non-recurring" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="domain.com" ta="0" tp="0" tt="D" ra="20.00" rp="1" rt="Y" rr="BN" rrt="" rra="1" image="default" output="button" expire="6/30" cutoff="3/31" /]
With the expire and cutoff values added to the shortcode, the custom function modifies the PayPal button:
- custom="domain.com" is appended with the expiration date "|YYYY-MM-DD"
- rp="1" is changed to the number of days remaining to and including the expiration date
- rt="Y" is changed to rt="D"
I use Simple/Shortcode Conditionals to hide this button from members above level 0.
Members above level 0 have active memberships with an EOT already configured for the desired month/day. With Fixed-Term Extensions set to Yes, I use this shortcode to allow renewals of one year:
[s2Member-PayPal-Button level="1" ccaps="" desc="Individual Member / non-recurring" ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="domain.com" ta="0" tp="0" tt="D" ra="20.00" rp="1" rt="Y" rr="BN" rrt="" rra="1" image="default" output="button" /]
Again, if any of this looks as if it will break something important, please say so.
Thanks!