Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kimwhite/38dbc079e0f6cf333ad1ea05a8f5bae6 to your computer and use it in GitHub Desktop.
Save kimwhite/38dbc079e0f6cf333ad1ea05a8f5bae6 to your computer and use it in GitHub Desktop.
Use a custom checkout_renewal.html email template for renewal purchases in Paid Memberships Pro
<?php // do not copy this line.
/**
* This recipe will let you create a unique email for renewals.
*
* You must add this recipe to your site by creating a custom plugin
* Read this companion article for step-by-step directions
* https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/
*/
/*
Use a custom checkout_renewal.html email template for renewals.
Make sure there is a folder /email/ in the plugin folder.
Add a file /email/checkout_renewal.html in that email folder.
/plugins/pmpro-customizations/email/checkout_renewal.html
*/
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 = $order->is_renewal();
if(!$is_renewal)
return $email;
//this is a renewal! let's do our stuff
//update subject
$email->subject = "Thank you for your renewal.";
//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', 20);
@kimwhite
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment