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.

automatic renewal reminder

Home Forums Community Forum Unofficial Extensions/Hacks automatic renewal reminder

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

Topic Author Topic
Posted: Friday Sep 7th, 2012 at 4:31 pm #24564

Hi,

I read up on the fora and I understand that s2member currently has no automatic renewal notification. So I wrote my own and put it in a plugin. It appears to be working correctly, but since I have a mixed subscription payment set-up (PayPal and cash/cheque), I’m concerned that I might not always be retrieving the carrect renewal date. Could you have a look, please?

register_activation_hook(__FILE__, 'ashweb_activation');
add_action('ashrenewalmsg','ash_check_for_renewals');

function ashweb_activation(){
	wp_schedule_event(current_time('timestamp'), 'daily', 'ashrenewalmsg');
}
register_deactivation_hook(__FILE__, 'ashweb_deactivation');

function ashweb_deactivation() {
	wp_clear_scheduled_hook('ashrenewalmsg');
}



function ash_check_for_renewals(){
	$users=get_users(array());
	if(empty($users)) return;
	
	$arr=array();
	$blogname = get_bloginfo("name");
	$headers= <<<EOH
From: $blogname '<membership@example.com>';
Content-Type: text/html;
EOH;
	foreach($users as $user){
		$ts=get_user_field ("s2member_auto_eot_time", $user->ID);//EOT set manually
		if(!$ts){
			$ts=get_user_field(s2member_last_payment_time, $user->ID);//user paid by PayPal
			if(!$ts) continue;//user didn't pay
			$eot=new DateTime("@$ts");
			$eot->modify('+1 year'); //all my memberships are 1 year long
		} else {
			$eot = date_create("@$ts");
		}

		$nts=get_user_field('ash_renewal_notice',$user->ID); //timestamp or empty
		$notification= empty($nts) ? new DateTime : new DateTime("@$nts");

		//I'd be using all DateTime methods but I'm stuck with PHP5.2
		$not=$notification->format('U');
		$ts= $eot->format('U');
		$now= time(); 
		$diff=$ts - $now;
		$notdiff = $not - $ts;

		if($diff >= 0 && $diff < 604800) { //EOT will occur within the next 7 days
			if($nts && $notdiff < 0 && $notdiff > -604800) continue; //notification done within last 7 days
			($nts) ? update_user_meta($user->ID,  'ash_renewal_notice',$not) : add_user_meta($user->ID, 'ash_renewal_notice', $not); //set a user meta flag so notification not repeated

			$emailtext = <<< EOT
<style>
p{padding-bottom:1em;}
dt{font-weight: bold;padding-top:0.5em}
dd{margin: 0 2em 0.3em; 0}
</style>
<p>Dear {$user->display_name},</p>

<p>Your ASH membership comes up for renewal on {$eot->format('Y-m-d')}. We hope you will be joining us
again this year. </p>
<p>Your user name is <strong>{$user->user_login}</strong>. If you've forgotten your password, you can recover it <a href='http://example.ca/wp-login.php?action=lostpassword'>here</a>. If you have any difficulties, please contact the Membership Chair by email (<a href='mailto:membership@example.ca'>membership@example.ca</a>).</p>

<p>We look forward to seeing you again soon!<br>
<em>ASH<br>
<a href='http://example.ca'>http://example.ca</a>
</em>
</p>
EOT;
			wp_mail($user->user_email, 'Time to renew your ASH membership', $emailtext, $headers);
			$arr[]="<p>{$user->display_name} {$user->user_email} {{$eot->format('Y-m-d')}}</p>";
		}

	}
	$contents=print_r($arr,true);
	wp_mail('web@example.ca','ASH renewals sent', $contents, $headers);
}

Thanks

  • This topic was modified 4 years, 2 months ago by  Cristián Lávaque. Reason: Moved to the User Hacks forum

List Of Topic Replies

Viewing 1 replies (of 1 total)
Author Replies
Author Replies
Posted: Saturday Sep 8th, 2012 at 8:46 am #24634
Raam Dev
Username: Raam
Staff Member

Hello,

It looks right to me, but the best way to make sure is to simply test it. I recommend testing with a $0.01 transaction on PayPal so you can mimic a renewal notification.

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