|
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. :)
|
|
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?
|
|
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.
|
|
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?
|
|
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]
|
|
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?
|
|
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]
|
|
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?
|
|
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.
|
|
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
|
|
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.
|
|
Thanks, I will try that :)
|
|
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?
|
|
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);
}
}
|
|
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?
|
|
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
|
|
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.
|
|
This also returns EOT as “todays date + one year”, not “current year+1/12/31” as desired.
|
|
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);
}
|
|
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.
|
|
Ok, thank you for all the help :)
|
|
This sounds like exactly what I am after too! eBierek, if you figure out a solution would you mind posting it here?
|
|
@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.
|