latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Date based EOT instead of fixed duration

Home Forums Community Forum Date based EOT instead of fixed duration

Tagged: ,

This topic contains 3 replies, has 2 voices. Last updated by  Raam Dev 4 years, 3 months ago.

Topic Author Topic
Posted: Monday Oct 8th, 2012 at 6:21 pm #27834

I read several threads that recommend using PHP’s date() function to calculate a custom duration based on the current date; but I am still ignorant about how to input this calculated number of days into the rp=”” value of a button shortcode… or if that’s where it goes at all. Several threads spoke of PayPal Pro forms. I do not have a PayPal Pro account.

Where do I store my code, and how do I use it in a PayPal button?

The following code is my logic to calculate the number of days until a date-based expiration. A year is added to the count if the current date is within three months of the expiration date.

$now = time();
$cutoff = strtotime('4/1');
$expire = strtotime('7/1');
if($now > $cutoff) {
  $expire = strtotime(date("Y-m-d", $expire) . "+1 year");
}
$timeleft = $expire-$now;
$daysleft = round((($timeleft/24)/60)/60) + 1;
echo $daysleft;

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Tuesday Oct 9th, 2012 at 6:05 am #27868
Raam Dev
Username: Raam
Staff Member

Hi Quentin,

The two shortcode attributes you’ll need to use are rp=”” and rt=””. Here’s what Dashboard -› s2Member® -› PayPal® Buttons -› Shortcode Attributes (Explained) says about those:

rp=”1″ Regular Period. Only valid w/ Membership Level Access and/or Independent Custom Capabilities. Must be >= 1 ( ex: 1 Week, 2 Months, 1 Month, 3 Days ).

rt=”M” Regular Term. Only valid w/ Membership Level Access and/or Independent Custom Capabilities. Possible values: D = Days, W = Weeks, M = Months, Y = Years, L = Lifetime.

The code you provided above gives the result in days, so you should set rt=”D”. Now, you’ll need to dynamically add the number of days into the rp=”” attribute (scroll over to the rp=”” attribute to see the PHP code):

[s2Member-PayPal-Button level="1" ccaps="" desc="Bronze Member / Description and pricing details here." ps="paypal" lc="" cc="USD" dg="0" ns="1" custom="example.com" ta="0" tp="0" tt="D" ra="0.01" rp="<?php echo $daysleft; ?>" rt="D" rr="1" rrt="" rra="1" image="default" output="button" /]

Now, whenever the PayPal button loads on your page, it will automatically be configured with the result in $daysleft. Keep in mind that you will need to be using a plugin like Exec-PHP to run PHP code inside your WordPress Page.

Posted: Tuesday Oct 9th, 2012 at 5:37 pm #27932

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!

Posted: Wednesday Oct 10th, 2012 at 4:50 am #27963
Raam Dev
Username: Raam
Staff Member

Quentin,

That looks good to me! Thanks very much for sharing your code here.

Awarded Quentin the Helpful and Advanced badges.
Viewing 3 replies - 1 through 3 (of 3 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.