Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save JarrydLong/e67809d7246a591fb96af55b05c26c84 to your computer and use it in GitHub Desktop.
Save JarrydLong/e67809d7246a591fb96af55b05c26c84 to your computer and use it in GitHub Desktop.
Use a custom checkout_renewal.html email template for renewal purchases in Paid Memberships Pro
/*
Use a custom checkout_renewal.html email template for renewals.
Add this code to a custom plugin.
Make sure there is a folder /email/ in the plugin folder.
Add a file /email/checkout_renewal.html in that email folder.
*/
function my_pmpro_email_checkout_renewal($email) {
$replace_data_again = false;
//only filter emails with invoices
if(empty($email->data['invoice_id']))
return $email;
//get order
$order = new MemberOrder($email->data['invoice_id']);
//make sure we have a real order
if(empty($order) || empty($order->id))
return $email;
//check if there has been another order for the same user/level in the past
global $wpdb;
$is_renewal = $wpdb->get_var("SELECT id FROM $wpdb->pmpro_membership_orders WHERE user_id = '" . $order->user_id . "' AND membership_id = '" . $order->membership_id . "' AND id <> '" . $order->id . "' AND status NOT IN('refunded', 'review', 'token', 'error') AND gateway_environment = '" . $order->gateway_environment . "' LIMIT 1");
if(!$is_renewal)
return $email;
//this is a renewal! let's do our stuff
//update subject
$email->subject = "Thank you for your application.";
//update body
$email->body = file_get_contents(dirname(__FILE__) . "/email/checkout_renewal.html");
//replace data
if(is_string($email->data))
$email->data = array("body"=>$email->data);
if(is_array($email->data)) {
foreach($email->data as $key => $value) {
$email->body = str_replace("!!" . $key . "!!", $value, $email->body);
}
}
return $email;
}
add_filter('pmpro_email_filter', 'my_pmpro_email_checkout_renewal');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment