Skip to content

Instantly share code, notes, and snippets.

@LMNTL
Last active July 22, 2019 15:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LMNTL/fc22a6fc3d8079055f6f471475fd4fbc to your computer and use it in GitHub Desktop.
Save LMNTL/fc22a6fc3d8079055f6f471475fd4fbc to your computer and use it in GitHub Desktop.
properly show variables when using Email Templates Add On with Recurring Payment Reminders
// properly show variables when using Email Templates Add On with Recurring Payment Reminders
function my_pmproet_email_data( $data, $pmproemail )
{
if( $_REQUEST["action"] === 'pmproet_send_test' && $pmproemail->template === 'membership_recurring' )
{
$euser = get_user_by( "email", $pmproemail->email );
// Make sure we have a user.
if ( empty( $euser ) ) {
return $body;
}
//make sure we have the current membership level data
$euser->membership_level = pmpro_getMembershipLevelForUser( $euser->ID, true );
//some standard fields
$newdata = array(
"subject" => $pmproemail->subject,
"name" => $euser->display_name,
"user_login" => $euser->user_login,
"sitename" => get_option( "blogname" ),
"membership_id" => $euser->membership_level->id,
"membership_level_name" => $euser->membership_level->name,
"siteemail" => pmpro_getOption( "from_email" ),
"login_link" => wp_login_url(),
"enddate" => date( get_option( 'date_format' ), $euser->membership_level->enddate ),
"display_name" => $euser->display_name,
"user_email" => $euser->user_email,
"cancel_link" => wp_login_url( pmpro_url( "cancel" ) )
);
//get last order
$lastorder = new MemberOrder();
$lastorder->getLastMemberOrder( $euser->ID );
//figure out billing info
if ( ! empty( $lastorder->id ) ) {
//set renewal date
$newdata['renewaldate'] = date( get_option( "date_format" ), pmpro_next_payment( $euser->ID ) );
//update billing info
$billinginfo = "";
//get card type and last4
if ( ! empty( $lastorder->cardtype ) && ! empty( $lastorder->accountnumber ) ) {
$billinginfo .= $lastorder->cardtype . ": " . $lastorder->accountnumber . "<br />";
if ( ! empty( $lastorder->expirationmonth ) && ! empty( $lastorder->expirationyear ) ) {
$billinginfo .= "Expires: " . $lastorder->expirationmonth . "/" . $lastorder->expirationyear . "<br />";
//check if expiring soon
$now = current_time( "timestamp" );
$expires = strtotime( $lastorder->expirationyear . "-" . $lastorder->expirationmonth . "-01" );
$daysleft = ( $expires - $now ) * DAY_IN_SECONDS;
if ( $daysleft < 60 ) {
$billinginfo .= "Please make sure your billing information is up to date.";
}
}
} elseif ( ! empty( $lastorder->payment_type ) ) {
$billinginfo .= "Payment Type: " . $lastorder->payment_type;
}
if ( ! empty( $billinginfo ) ) {
$newdata['billinginfo'] = "<p>" . $billinginfo . "</p>";
} else {
$newdata['billinginfo'] = "";
}
}
if( is_array($data) )
$newdata = array_merge($newdata, $data);
return $newdata;
}
return $data;
}
add_filter("pmpro_email_data", "my_pmproet_email_data", 8, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment