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.

Setting Up EOT Notifications

Home Forums Community Forum Unofficial Extensions/Hacks Setting Up EOT Notifications

This topic contains 21 replies, has 16 voices. Last updated by  Kristen Symonds 2 years, 11 months ago.

Topic Author Topic
Posted: Wednesday Nov 7th, 2012 at 11:08 pm #30985
Bruce
Username: Bruce
Staff Member

Hack Description

If you're looking for a way to notify users their EOT date is coming up, or that they have reached their EOT date, this can be done fairly easily with a few lines of code and the use of the WordPress function wp_schedule_event(). The following can be done within a Must-Use Plugin, or mu-plugin. If you don't have a /wp-content/mu-plugins/ directory, create it. I called my mu-plugin s2hack_eot_notify.php.

Hack Instructions

Depending on what functionality you're looking for, this hack takes either 1 or 2 steps. If you're looking to notify users of an upcoming EOT date, you need to check out the functions outlined below. One of the below functions sets the EOT Notification date, and the other tells users when they are getting close to their EOT through the EOT Notification date.

If you're looking to simply send an email, or notify the user when they have reached their EOT date, the approach is much simpler.

Notify Users of an Upcoming EOT Date
When notifying users of an upcoming EOT date, you need to set up 2 functions to get this functionality. The first being a way to add a User Meta value for each user that has an EOT date based on the s2Member user meta value $wpdb->prefix.'s2member_auto_eot_time'.

These functions (which we have named s2hack_eot_notify_set() and s2hack_eot_notify()) hook into two WordPress functionalities which are the wp_loaded hook and wp_schedule_event / WP_Cron functionality.

Set Notification Timestamp

After we've created our Must Use plugin, the first function we want to create is s2hack_eot_notify_set(). This function will set a user meta value called s2_eot_notify_date which houses a timestamp. This function uses the wp_loaded hook which fires every time WordPress loads. Because this will be fired every time WordPress loads we want to make sure to waste as little memory as possible.

This version of this function sets up the Notification EOT date as 1 week before s2Member Automatically demotes/deletes the member. If you'd like to change the amount of time the user has, you can change the variable $time_to_sub:

add_action('wp_loaded', 's2hack_eot_notify_set');
/**/
function s2hack_eot_notify_set()
	{
		global $current_user, $wpdb;
		$time_to_sub = 604800; # The amount to substract from s2Member's EOT time to get notification time. 604800 = 1 week
		/**/
		if(!is_user_logged_in() || !$GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled']) # If the user isn't logged in, or the Automatic EOT system is disabled...
			return; # ...we don't need to do anything
		/* Otherwise... */
		if(($eot = get_user_meta($current_user->ID, $wpdb->prefix.'s2member_auto_eot_time', true)) && !($neot = get_user_meta($current_user->ID, 's2_eot_notify_date', true))):
			$neot = $eot - $time_to_sub;
			/**/
			if($neot > time()) # If the Notification EOT time is in the future
				add_user_meta($current_user->ID, 's2_eot_notify_date', $neot); # Add the Notification EOT time
		endif;
		if(!wp_next_scheduled('s2hack_eot_notify') && $GLOBALS['WS_PLUGIN__']['s2member']['o']['auto_eot_system_enabled'])
			wp_schedule_event(current_time('timestamp'), 'daily', 's2hack_eot_notify');
	}
Set Up the Notification Function

After we've set up the Notification EOT Times, we can then use these times to Notify Users. Within the above function we also set up a WP_Cron event. We'll use this event to notify users (Notice that this function doesn't do anything really other than delete the User Meta value as of yet. You can use wp_mail() within this function to notify users):

if(has_action('s2hack_eot_notify')) # Add action only if it exists
	add_action('s2hack_eot_notify', 's2hack_eot_notification');
function s2hack_eot_notification() # Function to be called daily
	{
		$n_eot = time();
		/**/
		if(is_array($eots = $wpdb->get_results("SELECT `user_id` AS `ID` FROM `".$wpdb->usermeta."` WHERE `meta_key` = 's2_eot_notify_date' AND `meta_value` != '' AND `meta_value` escape($n_eot)."' LIMIT 3"))):
			foreach($eots as $eot): # We need to loop through all of the IDs to send the data
				if(($user_id = $eot->ID) && is_object($user = new WP_User($user_id)) && $user->ID && !$user->has_cap('administrator')): # Set up variables
					delete_user_meta($user_id, 's2_eot_notify_date');
				/*
					* Here is where you would notify users of their EOT
					* Suggest using wp_mail() link: http://codex.wordpress.org/Function_Reference/wp_mail
					*
					* User's details available through $user
					* $user object WP_User link: http://codex.wordpress.org/Class_Reference/WP_User_Query
					*/
				endif;
			endforeach;
		endif;
	}

Tip: These functions are only to point you in the right direction. These functions as they are now will not function correctly. If you cannot set up your notifications, we recommend getting a Freelance developer to help you out, or creating a Forum topic (or both!). :-)

Notify Users They Have Reached their EOT Date
Notifying users when they reach their EOT date is much simpler. The way you would need to do this is to simply hook into the s2Member action hook ws_plugin__s2member_during_auto_eot_system_during_demote, and extract() the variables s2Member was using:

user_firstname.' '.$user->last_name.'" user_email.'>';
		$message = 'Uh-oh! You ran out of time! You were demoted from '.$existing_role.' to '.$demotion_role.'.';
		wp_mail($to, $subject, $message, $headers);
	}

Tip: this function is only meant to point you in the right direction. You still need to change this function to suit your WordPress installation. If you cannot set up your notifications, we recommend getting a Freelance developer to help you out, or creating a Forum topic (or both!). :-)

List Of Topic Replies

Viewing 21 replies - 1 through 21 (of 21 total)
Author Replies
Author Replies
Posted: Thursday Feb 21st, 2013 at 3:21 pm #42754

This is really a part of utmost importance to everyone with a medium to large userbase. It would be great if it could be integrated into the main UI and not as a quite difficult hack (difficult for the standard wordpress user/admin who cannot write PHP himself).

Can I expect it to be integrated rather soon? (It’s great that after what seems to me like 1 year without nearly any change on the functionality, during the last month quite a lot of really needed little functionality got integrated).

Also it would be great to have another reminder X days after demotion.
Nearly all other membership plugins handle this point. S2member still doesn’t..

(BTW in February 2012 this feature was promised to launch in March (2012))

Posted: Tuesday Feb 26th, 2013 at 10:54 am #43247

This makes very little sense to me, is there any chance you can upload the plugin you have created?

Posted: Wednesday Feb 27th, 2013 at 9:32 am #43317
Eduan
Username: Eduan
Moderator

Dave, this is not really a plugin, this is a hack of sorts. And he has provided the code, so there’s nothing to upload. :)

If you want to use this hack you’ll have to study code until you can understand what this hack does, so that you’re able to edit it to your specific needs.

– Eduan

Posted: Thursday Mar 7th, 2013 at 11:11 am #43962
Robert Funge
Username: godrob

Hi Bruce,

Can this be modified please to include requiring payments setup from a paypal pro form? It would be great to be able to email paid subscribers x days before their membership is set to auto renew.

Thanks
Rob.

Posted: Tuesday Mar 12th, 2013 at 6:22 pm #44432
Eduan
Username: Eduan
Moderator

Hello Robert,

I believe currently this hack only works if the user has paid for access, otherwise he wouldn’t have an EOT, which is when the hack sends an email. :)

Also, this feature is in the plans for the next generation of s2Member, which should come out in the later part of the year. :)

– Eduan

Posted: Wednesday Mar 13th, 2013 at 1:28 pm #44504
Juan Vanegas
Username: juanjo

Hi guys, need some advice of how to achive the following

Have setup a subscription wich is 7 day free trial and then charge “x” amout for 1 moth subscription, up to here everything is nice and smooth, what i need to do is, setup a mail wich will be send 2 days before the trial EOT ( the 5th day after subscribing ), so the user have the option to cancell the subscription before been charge, if they want to.

So im been trying for some time to setup EOT remainder for a while now following steps in this post, no luck yet,

So any suggestion of how to make this work .. thanks one more time for the help

Posted: Thursday Apr 4th, 2013 at 1:52 pm #46626

As I am not a coder I have asked a developer to set up notifications for me. It seems that the user has to be logged in within a week of the expiry time to trigger the email.

I asked the developer to do it so that it would send an email without the user having to be logged in but it seems that this entails a whole bunch of other required set ups. He provided a set up that in his words “looped on all users to set mail trigger time for them” but this uses too much memory. Now he is saying that the a queueing system needs to be set up on the server “so that the main WordPress set up doesn’t suffer from db loops”.

Does it really need to be this complicated just to tell a user their membership is expiring soon?

Many thanks

Chris

Posted: Wednesday May 8th, 2013 at 3:20 pm #49504

Can I bump this topic?

I’m with these guys… need a simpler, sure fire way to send an EOT notification.

I motion to up this topic to priority ‘yesterday’.

Posted: Thursday May 9th, 2013 at 7:42 am #49581

I second Jordan’s point!

Posted: Friday Jun 7th, 2013 at 8:01 pm #51637
Jorge
Username: mastrapa

I’m here with Jordan and Ben,

Can we have this as one of the priorities to be included..

This will work great in conjunction with “prorated” upgrades..

J.

Posted: Friday Jun 7th, 2013 at 11:24 pm #51646

Hello S2M!

It seems that there is quite an interest (or… demand) in having automatic EOT notifications. Would one of the support reps please bring this up within the devs and let us know if this is in the works?

I think it’s a VERY necessary feature to avoid suprising charges our customers have forgotten about.

Thanks!

Posted: Thursday Jun 13th, 2013 at 6:45 pm #51905
Eduan
Username: Eduan
Moderator

Hello Jordan,

It is in the works. :)

A beta version of the next generation of s2Member should be available later this year, the full release will include this. :)

– Eduan

Posted: Thursday Jun 20th, 2013 at 12:11 am #52259
Clayton Corey
Username: ccorey

The only way the members on my site will be notified of the renewal is through PayPal. This is not the optimal resolution to this issue, and the update will be certainly a big help. We run a non profil organization with a few hundred members and I purchased the Pro version assuming this was part of the package. I would be willing to try the beta as I am not confident enough to write the hack. Is there a way I can be notified when this beta version becomes available? Email: ccorey@uplaunch.com. Thank you.

Posted: Monday Jun 24th, 2013 at 8:46 am #52459

Hi Bruce,

I should have also added a big thank you for this piece! I have found your code and explanation a useful starting point – and I looking forward to what’s to come.

Have you written any code that reminds members a week or a month after their EoT (obviously not if they have renewed successfully)?

Ideally I’d avoid over complicating matters, but I was thinking either:
1. Schedule the reminder event at the user’s EoT (and amend the signup process to cancel the scheduled event if they signup in the meantime), or
2. Record the user id and reminder timestamp in a separate table and query that table regularly (eg daily).

My suspicion is that 1) would be negatively impact large databases while 2) is a greater pain to maintain.
Any thoughts?
Thanks

Posted: Saturday Jul 20th, 2013 at 9:14 pm #53742
RH
Username: s2pm

I too am in need of this. Where can I get the beta version?

Posted: Thursday Jul 25th, 2013 at 2:18 am #54008
Danny Kim
Username: dannyk1m

I am also interested in what Ben said.

My client has their EOT date set at a specific date and would like e-mail to be sent to the members 30, 60, and 90 days after their EOT has passed. (assuming they haven’t renewed their membership)
I installed WP Crontrol and would like to know what hook/script to add to the hook input to make this happen.
I already have the e-mail script setup. Just need the script that says ‘when’ to send the e-mail.

Posted: Monday Dec 30th, 2013 at 10:54 am #62249

Hi,

Sorry for posting on this old thread again. Is it working for anyone? Or anything else?

There are some code errors too. Mr Bruce, can you guide me how to accomplish this? Or tell me this little more specifically.

Thanks in advance.

Posted: Thursday Jan 2nd, 2014 at 5:37 pm #62374

I wrote a plugin for automatic EOT notifications after several clients requested it:

http://s2renewalreminders.com/

It sends a customizable notification 7 days before EOT and then again 1 day before EOT.

Hope it’s okay to post it here.

Posted: Thursday Jan 2nd, 2014 at 11:05 pm #62376

@johnathon I’ve been waiting for a solution like this for almost a year. Shocked the authors haven’t made this a priority in a membership plugin. I’ll be checking your plugin out soon, thanks for posting!

Posted: Friday Jan 3rd, 2014 at 2:04 pm #62405

@jordiniman You’re welcome. Let me know if you have any questions. Here’s a coupon code that will save you a few bucks: jordan14

Posted: Wednesday Jan 15th, 2014 at 8:14 pm #62622

I am probably going to need to try Johnathon’s plugin, but I had a go at implementing the above and it’s not doing anything… not really sure where the problem lies. Can anyone help? https://gist.github.com/kristarella/bc75708b0b74c9b031aa

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