Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Replace the text that is added to confirmation emails and confirmation page by the Gift Levels add-on
<?php
// Copy from below here...
/*
* Replace the text that is added to confirmation emails and confirmation page by the Gift Levels add-on
* As written, will just show the code instead of the link to checkout with the code.
*/
function my_pmprogl_customize_message() {
remove_filter("pmpro_email_body", "pmprogl_pmpro_email_body", 10, 2);
add_filter("pmpro_email_body", "my_pmprogl_pmpro_email_body", 10, 2);
remove_filter("pmpro_confirmation_message", "pmprogl_pmpro_confirmation_message");
add_filter("pmpro_confirmation_message", "my_pmprogl_pmpro_confirmation_message");
}
add_filter("init", "my_pmprogl_customize_message");
function my_pmprogl_pmpro_email_body($body, $pmpro_email)
{
global $wpdb, $pmprogl_gift_levels, $current_user;
//only checkout emails, not admins
if(strpos($pmpro_email->template, "checkout") !== false && strpos($pmpro_email->template, "admin") == false)
{
//get the user_id from the email
$user_id = $wpdb->get_var("SELECT ID FROM $wpdb->users WHERE user_email = '" . $pmpro_email->data['user_email'] . "' LIMIT 1");
$level_id = $pmpro_email->data['membership_id'];
//get the user's last purchased gift code
$gift_codes = get_user_meta($current_user->ID, "pmprogl_gift_codes_purchased", true);
if(is_array($gift_codes))
$code_id = end($gift_codes);
if(!empty($code_id))
{
$discount_code = $wpdb->get_var("SELECT code FROM $wpdb->pmpro_discount_codes WHERE id = '" . intval($code_id) . "' LIMIT 1");
if(!empty($discount_code)) {
$body = "<p><strong>Share this discount code with your gift recipient: " . $discount_code . "</strong></p>" . $body;
}
}
}
return $body;
}
/*
Show last purchased gift code on the confirmation page.
*/
function my_pmprogl_pmpro_confirmation_message($message)
{
global $current_user, $pmprogl_gift_levels, $wpdb;
//which level purchased
$level_id = intval($_REQUEST['level']);
//only if there is a gift for this level
if(!empty($pmprogl_gift_levels) && !empty($pmprogl_gift_levels[$level_id]))
{
//get the user's last purchased gift code
$gift_codes = get_user_meta($current_user->ID, "pmprogl_gift_codes_purchased", true);
if(is_array($gift_codes))
$last_code_id = end($gift_codes);
if(!empty($last_code_id))
{
$discount_code = $wpdb->get_var("SELECT code FROM $wpdb->pmpro_discount_codes WHERE id = '" . intval($last_code_id) . "' LIMIT 1");
if(!empty($discount_code)) {
$message = "<p><strong>Share this discount code with your gift recipient: " . $discount_code . "</strong></p>" . $message;
}
}
}
return $message;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.