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