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.

Show Next Subscription Payment Workaround…

Home Forums Community Forum Show Next Subscription Payment Workaround…

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

Topic Author Topic
Posted: Tuesday Oct 23rd, 2012 at 7:16 am #29377
Robert Funge
Username: godrob

Hi guys,

I know S2Member doesn’t as yet support the ability to show the next payment date of a paypal pro subscription out-of-the-box, but I was wondering whether anybody could help me so I can manually add a fixed time period to ‘$s2member_last_payment_time’ which would achieve the same thing, i.e., a date in the future, according to a members Level?

Here’s the code I’m using to successfully show a members last payment date:

<?php
$s2member_last_payment_time = get_user_field('s2member_last_payment_time');
if (!empty($s2member_last_payment_time)) 
	echo 'Last Payment: ' . date('M-d-Y', $s2member_last_payment_time);
?>

My Levels:

LEVEL2 1 Month Membership = s2member_last_payment_time + 1 Month
LEVEL3 3 Month Membership = s2member_last_payment_time + 3 Months
LEVEL4 6 Month Membership = s2member_last_payment_time + 6 Months
LEVEL5 12 Month Membership = s2member_last_payment_time + 12 Months

So for example, if a member is on LEVEL2 then I need to be able to show their next billing date by echoing $s2member_last_payment_time + 1 month. Equally then, if they are on LEVEL 5 then I need to echo $s2member_last_payment_time + 12 months

Any ideas how I can achieve this please?

Thanks
Rob.

List Of Topic Replies

Viewing 5 replies - 1 through 5 (of 5 total)
Author Replies
Author Replies
Posted: Tuesday Oct 23rd, 2012 at 1:01 pm #29423
Raam Dev
Username: Raam
Staff Member

This should work:

<?php 
$s2member_last_payment_time = get_user_field('s2member_last_payment_time');
if (!empty($s2member_last_payment_time)) 
	echo 'Last Payment: ' . date('M-d-Y', $s2member_last_payment_time);
	echo 'LEVEL2 1 Month Membership: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +1 month"); 
?>
Posted: Wednesday Oct 24th, 2012 at 10:20 am #29516
Robert Funge
Username: godrob

Hi Raam, thanks for your reply. I’ve tried this:

<?php
$s2member_last_payment_time = get_user_field('s2member_last_payment_time');
if (!empty($s2member_last_payment_time)) 

if(current_user_is("S2member_level2"))
    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +1 month");
elseif (current_user_is("S2member_level3"))
    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +3 month");
elseif (current_user_is("S2member_level4"))
    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +6 month");
elseif (current_user_is("S2member_level5"))
    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +12 month");
?>

…but it doesn’t work. I Just get a blank space where the output of ‘s2member_last_payment_time’ should be. Even though I know that the field is populated because it correctly works without the +1 month etc etc

Any ideas?

Thanks again
Rob

Posted: Wednesday Oct 24th, 2012 at 2:45 pm #29563
Raam Dev
Username: Raam
Staff Member

The first thing I noticed is that your code is missing the curly brackets for the first if-block. It should be:

<?php
$s2member_last_payment_time = get_user_field('s2member_last_payment_time');
if (!empty($s2member_last_payment_time)) {
	if(current_user_is("S2member_level2"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +1 month");
	elseif (current_user_is("S2member_level3"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +3 month");
	elseif (current_user_is("S2member_level4"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +6 month");
	elseif (current_user_is("S2member_level5"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +12 month");
}

?>

Any if-blocks that contain more than one line below the conditional must use curly brackets. Your other if-blocks only contain one line (the echo line), so they don’t need the curly brackets.

The second thing I recommend is testing the various assumptions by echo’ing different variables and statements to confirm they contain the data you’re expecting. For example:

<?php
$s2member_last_payment_time = get_user_field('s2member_last_payment_time');

echo 'DEBUG: $s2member_last_payment_time contains ' . $s2member_last_payment_time;

if (!empty($s2member_last_payment_time)) {
	if(current_user_is("S2member_level2"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +1 month");
	elseif (current_user_is("S2member_level3"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +3 month");
	elseif (current_user_is("S2member_level4"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +6 month");
	elseif (current_user_is("S2member_level5"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +12 month");
}

?>

Finally, I noticed your usage of current_user_is(“S2member_level2”) is incorrect: it should be s2member_level2, with a lowercase ‘s’, not uppercase.

So the final code I suggest testing is:

<?php
$s2member_last_payment_time = get_user_field('s2member_last_payment_time');

echo 'DEBUG: $s2member_last_payment_time contains ' . $s2member_last_payment_time;

if (!empty($s2member_last_payment_time)) {
	if(current_user_is("s2member_level2"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +1 month");
	elseif (current_user_is("s2member_level3"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +3 month");
	elseif (current_user_is("s2member_level4"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +6 month");
	elseif (current_user_is("s2member_level5"))
	    echo 'Next Payment: ' . strtotime(date("M-d-Y", $s2member_last_payment_time) . " +12 month");
}

?>
Posted: Thursday Oct 25th, 2012 at 5:30 am #29621
Robert Funge
Username: godrob

Hi Raam, thanks for your detailed reply. It works!!!

Just one little problem. In my test example the output reads as a unix time stamp – e.g. 1353456000 If I convert that figure using an online tool then I get the correct date in the future.

So, how do I covert this into a human readable date format using the code above.

Thanks for you help with this.

Regards
Rob.

  • This reply was modified 4 years, 2 months ago by  Robert Funge.
Posted: Thursday Oct 25th, 2012 at 2:03 pm #29671
Raam Dev
Username: Raam
Staff Member

Robert,

That’s what the PHP date() function does (docs here).

<?php
	echo date("M-d-Y", $unixtime_formatted_date); // outputs format: Jan 04 2012
?>
Viewing 5 replies - 1 through 5 (of 5 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.