Forked from strangerstudios/my_pmpro_email_checkout_renewal.php
Last active
January 23, 2023 15:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); |
This snippet is include on tool tip https://www.paidmembershipspro.com/customize-membership-checkout-confirmation-email-membership-renewals/
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample checkout_renewal.html page here: https://gist.github.com/kimwhite/73189be1bf59c0dec736b07b84bf4f02