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.

Update EOT for existing (logged in) user

Home Forums Community Forum Update EOT for existing (logged in) user

Tagged: ,

This topic contains 23 replies, has 4 voices. Last updated by  eBierek 3 years, 9 months ago.

Topic Author Topic
Posted: Sunday Mar 10th, 2013 at 7:19 am #44195
eBierek
Username: eBierek

Hi,

I’m using the function below to set EOT for all members, depending on access level. For new users and demoted users (level0) it works fine. But for existing users (logged in and level 1) that renew their membership, EOT is not updated. Everything for the existing user is updated but not the EOT, I can see that in wp-admin.
Do I need another hook to update users EOT than those below? Would you check the code please?

If a user (level 1) has a membership ending 2013-12-31, and they renew, EOT should be updated to 2014-12-31. But it currently stays on 2013-12-31.

add_action ("ws_plugin__s2member_during_configure_user_registration_front_side", "my_fixed_EOT_time");
add_action ("ws_plugin__s2member_during_paypal_notify_during_subscr_signup_w_update_vars", "my_fixed_EOT_time");
add_action ("ws_plugin__s2member_during_paypal_notify_during_subscr_modify", "my_fixed_EOT_time");
function my_fixed_EOT_time ($vars)
    {
		// Set EOT based on access level
		if (current_user_is("s2member_level4")){ 
			//Level 4 Members.
				
		} else if (current_user_is("s2member_level1")){ 
			// Add one year to current year and set EOT - Level 1 (members)
			$expire_on = date("Y", strtotime("+ 1 year")) . "-12-31";
			update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);	
		
		} else if (current_user_is("s2member_level0")){ 
			// Demoted unpaid members end up here if they fail to pay before current year/12/31
			$expire_on = strtotime ( date('Y') . '-12-31');
			update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
		
		} else { 
			// Set EOT to current year for NEW users - not logged in
			$expire_on = strtotime ( date('Y') . '-12-31');
			update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
		} 
    }

Thank you in advance,
Emily

List Of Topic Replies

Viewing 23 replies - 1 through 23 (of 23 total)
Author Replies
Author Replies
Posted: Tuesday Mar 12th, 2013 at 11:24 am #44376

Hi Emily.

If you’re selling with a single payment (buy now), you can let s2Member extend the access for you. [hilite path]Dashboard -› s2Member® -› PayPal® Options -› Automatic EOT Behavior -> Fixed-Term Extensions[/hilite]

If a user (level 1) has a membership ending 2013-12-31, and they renew, EOT should be updated to 2014-12-31. But it currently stays on 2013-12-31.

Is it being updated at all? You could test adding a unique date (one that would not have been added by your code otherwise) to see if it comes up in the profile, e.g.:

[hilite pre_code]
$expire_on = "2020-12-31";
[/hilite]

By the way, since it’s an extension, I’d first get the EOT time in his profile and then add the year to that.


I hope that helps. :)

Posted: Wednesday Mar 13th, 2013 at 6:41 am #44474
eBierek
Username: eBierek

Hi Cristián,

Thank you for helping. I’m using the pro paypal forms for level #X, one year access. I tried your suggestion with the code below but nothing happens unfortunately.

else if (current_user_is("s2member_level1")){ 
$expire_on = "2020-12-31";
update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);	
}

I also tested the date for new users, setting it to a fixed date of “2020-12-31” but that gives me an EOT of “Thu Jan 01st, 1970”. Why is that?

else { 
$expire_on = "2020-12-31";
update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
} 

What could be wrong?

Is it

get_user_field('s2member_auto_eot_time'))) + 1 year

you mean? :) How would I do that if user is level 1-3?

Posted: Wednesday Mar 13th, 2013 at 11:13 am #44494
eBierek
Username: eBierek

Ok, I have tested alot and this works, it updates EOT:

function my_fixed_EOT_time ($vars) {
$date =  date('Y') . '-12-31'; //get current year and adds -12-31
$expire_on = strtotime ( '+1 year' , strtotime ( $date ) ) ; //add one year to current year
update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);	
}

But when I add the conditionals for different levels, it doesn’t work. Can’t I use

else if (current_user_is("s2member_level2")) {some code to add EOT}

in s2hacks.php? See first post for reference.

Posted: Thursday Mar 14th, 2013 at 7:48 am #44593
eBierek
Username: eBierek
function my_fixed_EOT_time ($vars) {
	if (current_user_is("s2member_level2")){ 
		$date =  date('Y') . '-12-31'; //get current year and adds -12-31
		$expire_on = strtotime ( '+1 year' , strtotime ( $date ) ) ; //add one year to current year
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);	
	}
}

This returns the right time, 1420002000 (unix time stamp) which is “Wed, 31 Dec 2014 05:00:00 GMT”. What am I missing? :) Unix time stamp is the right format for updating EOT, right?

Posted: Thursday Mar 14th, 2013 at 11:47 am #44622

Unix time stamp is the right format for updating EOT, right?

Right, I forgot the strtotime in my example. Very sorry about that…

But when I add the conditionals for different levels, it doesn’t work. Can’t I use
[hilite pre_code]
else if (current_user_is("s2member_level2")) {some code to add EOT}
[/hilite]

That condition looks fine, just make sure that the account you’re testing with has that role. It works for the other level roles, right?

[hilite pre_code]
$date = date('Y') . '-12-31'; //get current year and adds -12-31
$expire_on = strtotime ( '+1 year' , strtotime ( $date ) ) ; //add one year to current year
[/hilite]

You could also do:

[hilite pre_code]
$expire_on = strtotime((date('Y') + 1) . '-12-31');
[/hilite]
Posted: Thursday Mar 14th, 2013 at 12:35 pm #44630
eBierek
Username: eBierek

Hello again,

Setting EOT with conditionals works for new members and demoted members (level0) where EOT is empty. I have tested accounts logged in on level 1-3, no EOT update. But when I do following, without the (current_user_is(“s2member_level2”))-conditionals it works fine:

function my_fixed_EOT_time ($vars) {
$expire_on = strtotime((date('Y') + 1) . '-12-31');
update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);	
}

This is confusing. Is this a bug?

Posted: Monday Mar 18th, 2013 at 6:36 pm #45079

I don’t think it’s a bug. Maybe at that point in the script, the user’s account had not been changed to that role yet and thus the condition isn’t true?

Have you tried checking what the user’s role is at that point? Maybe with [hilite mono]S2MEMBER_CURRENT_USER_ACCESS_LEVEL[/hilite]. [hilite path]Dashboard -› s2Member® -› API / Scripting -› PHP/API Constants[/hilite]

Posted: Tuesday Mar 19th, 2013 at 8:52 am #45164
eBierek
Username: eBierek

Hello again,
Thank you for feedback.

Sorry if I confused you. Users account is the same all the time, we don’t have upgrades between levels unless a user is demoted for not paying on time.

So the senario is: Level 1 user logs in (I know for sure the level is right), it’s march 2013 (EOT currently set to 2013-12-31). During the month of march all members can renew their membership for upcoming year. When user does that/pays for another year, EOT should be set to 2014-12-31 (get current year and add one). And there is where it all fails, as the new EOT isn’t saved.

Payment with PayPal works and is registered, receipt is sent out from PayPal/S2, and Paid Subscr. ID is also updated.

What could be missing?

Posted: Wednesday Mar 20th, 2013 at 6:42 am #45215

I don’t know why the condition isn’t working in your hack, if the level role is correct. I guess that if that can’t be made to work, what I’d try would be having a separate function for the modification hook, so you don’t need any condition to know what to do there, you can just extend the EOT.

Posted: Wednesday Mar 20th, 2013 at 2:30 pm #45244
eBierek
Username: eBierek

Hi and thank you for trying to help :)

I have now two functions as you suggested. One for new members setting EOT to “current year-12-31” and one for members updating their account setting EOT to “(current year+1)-12-31”. This works great!

But we also need to handle demoted users. When they decides to finally pay again, their EOT should be set to the same as new users -> “current year-12-31”. Can we handle them with another hook? Right now they get one year too much. Advice much appreciated.
/Emily

Posted: Wednesday Mar 20th, 2013 at 9:53 pm #45277

Glad that approach worked. :)

What you can do is have a condition in that new function, that checks if Level is 0 then this year, else next year. See if that works.

Posted: Thursday Mar 21st, 2013 at 4:17 am #45308
eBierek
Username: eBierek

Thanks, I will try that :)

Posted: Thursday Mar 21st, 2013 at 5:27 am #45314
eBierek
Username: eBierek

Since a demoted user still is considered to be a “user that will updated” I need to work with these, right?:

add_action ("ws_plugin__s2member_during_paypal_notify_during_subscr_signup_w_update_vars", "my_fixed_EOT_time_upd");
add_action ("ws_plugin__s2member_during_paypal_notify_during_subscr_modify", "my_fixed_EOT_time_upd");

That also handles change for other users (level1-3). So I tried following:

function my_fixed_EOT_time_upd ($vars)
{
	if (current_user_is("s2member_level0")){ 
		$expire_on = strtotime ( date('Y') . '-12-31');
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
	
	} else { 
		$expire_on = strtotime((date('Y') + 1) . '-12-31');
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
	} 
}

This still gives me “current year + one year” even if the user is demoted (level0). Maybe the hooks cant handle conditions? Do you know of others that have tried this?

Posted: Friday Mar 22nd, 2013 at 5:33 pm #45521
Bruce
Username: Bruce
Staff Member

This still gives me “current year + one year” even if the user is demoted (level0). Maybe the hooks cant handle conditions? Do you know of others that have tried this?

These hooks can’t use the current_user_is() or current_user_can() conditionals because current User is not yet set in WordPress at this point. However, s2Member does pass you the User that it’s currently working with in the $vars array. You can do the following:

add_action ("ws_plugin__s2member_during_paypal_notify_during_subscr_signup_w_update_vars", "my_fixed_EOT_time_upd");
add_action ("ws_plugin__s2member_during_paypal_notify_during_subscr_modify", "my_fixed_EOT_time_upd");
function my_fixed_EOT_time_upd ($vars)
{
	if (user_is($vars["user_id"], 'subscriber')) { 
		$expire_on = strtotime ( date('Y') . '-12-31');
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
	
	} else { 
		$expire_on = strtotime((date('Y') + 1) . '-12-31');
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
	} 
}
Posted: Sunday Mar 24th, 2013 at 10:15 am #45587
eBierek
Username: eBierek

Hi Bruce, thanks for helping :)

I have tried this and it still gives me (date(‘Y’) + 1) even if the user is a “subscriber”. Where in the process, is EOT set/updated? Has the user role already changed from “subscriber” to “level1-user” at that time?

Posted: Tuesday Mar 26th, 2013 at 7:35 pm #45819
Bruce
Username: Bruce
Staff Member

Thanks for the follow-up.

I have tried this and it still gives me (date(‘Y’) + 1) even if the user is a “subscriber”. Where in the process, is EOT set/updated? Has the user role already changed from “subscriber” to “level1-user” at that time

The hooks you’re using are near the end of s2Member’s processes for modifications, after a User has been Modified. If you’re looking for hooks before a User is modified, try these:

ws_plugin__s2member_during_paypal_notify_during_before_subscr_modify
ws_plugin__s2member_during_paypal_notify_before_subscr_signup_w_update_vars
Posted: Thursday Mar 28th, 2013 at 11:42 am #45979
eBierek
Username: eBierek

Hi,

I’m sorry to say this doesn’t work either.

add_action ("ws_plugin__s2member_during_paypal_notify_during_before_subscr_modify", "my_fixed_EOT_time_upd");
add_action ("ws_plugin__s2member_during_paypal_notify_before_subscr_signup_w_update_vars", "my_fixed_EOT_time_upd");

function my_fixed_EOT_time_upd ($vars)
{	
	//If user is demoted to subrsciber
	if (user_is($vars["user_id"], 'subscriber')) { 
		$expire_on = strtotime ( date('Y') . '-12-31');
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
	//elseif user is renewing active membership
	} else { 
		$expire_on = strtotime((date('Y') + 1) . '-12-31');
		update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
	} 
}

It still gives me (date(‘Y’) + 1) even if the user is a ‘subscriber’ (demoted). What can I use here? Many thanks.

Posted: Thursday Mar 28th, 2013 at 12:04 pm #45981
eBierek
Username: eBierek

This also returns EOT as “todays date + one year”, not “current year+1/12/31” as desired.

Posted: Thursday Mar 28th, 2013 at 1:12 pm #45985
eBierek
Username: eBierek

Is there a way I can split these roles up (by hook), just as Cristián suggested for the new users?

This should catch existing users when they renew their active account, and sets EOT to current year+1/12/31

add_action (" ? ", "my_fixed_EOT_time_upd");
function my_fixed_EOT_time_upd ($vars)
{	
$expire_on = strtotime((date('Y') + 1) . '-12-31');
update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
}

This should catch demoted users when they decide to pay, and upgrades from level 0 to 1, and sets EOT to current year/12/31

add_action (" ? ", "my_fixed_EOT_time_upg");
function my_fixed_EOT_time_upg ($vars)
{	
$expire_on = strtotime ( date('Y') . '-12-31');
update_user_option ($vars["user_id"], "s2member_auto_eot_time", $expire_on);
}
Posted: Sunday Mar 31st, 2013 at 7:31 pm #46218
Bruce
Username: Bruce
Staff Member

Thanks for the follow-up.

I’m sorry to say that I can’t really debug this any further for you. I would recommend dumping the variables from your hooks and see if you can find where there is a difference between Users being upgraded and not. If you can’t find any way to distinguish based on what s2Member is passing you, I might suggest just adding a year to the User’s current End of Term if it is already set. That should work equally well, I think. Perhaps something like this:

add_action ("ws_plugin__s2member_during_paypal_notify_during_before_subscr_modify", "my_fixed_EOT_time_upd");
add_action ("ws_plugin__s2member_during_paypal_notify_before_subscr_signup_w_update_vars", "my_fixed_EOT_time_upd");

function my_fixed_EOT_time_upd ($vars)
{	
	//If user is demoted to subrsciber
	
	$current = get_user_field ('s2member_auto_eot_time', $vars['user_id']);
	
	if(!$current) { 
		$expire_on = strtotime ( date('Y') . '-12-31');
		update_user_option ($vars["user_id"], 's2member_auto_eot_time', $expire_on);
	//elseif user is renewing active membership
	} else { 
		$expire_on = strtotime((date('Y') + 1) . '-12-31');
		update_user_option ($vars["user_id"], 's2member_auto_eot_time', $expire_on);
	} 
}
That’s as far as we can go with custom code. If you need further assistance, we recommend http://jobs.wordpress.net, or another freelance web site where WordPress® experts are offering their expertise through a bid on your project.
Posted: Wednesday Apr 3rd, 2013 at 3:57 am #46451
eBierek
Username: eBierek

Ok, thank you for all the help :)

Posted: Wednesday Apr 3rd, 2013 at 10:31 am #46468

This sounds like exactly what I am after too! eBierek, if you figure out a solution would you mind posting it here?

Posted: Thursday Apr 4th, 2013 at 2:21 pm #46627
eBierek
Username: eBierek

@Rick: Sure :)
It’s working for new members and renewing members but demoted members which have to upgrade from level 0 to 1 seems difficult to solve.

Viewing 23 replies - 1 through 23 (of 23 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.