Skip to content

Instantly share code, notes, and snippets.

@strangerstudios
Last active April 12, 2021 22:29
Show Gist options
  • Save strangerstudios/d2806e3ac91b2e24c304 to your computer and use it in GitHub Desktop.
Save strangerstudios/d2806e3ac91b2e24c304 to your computer and use it in GitHub Desktop.
Send a short email/text message/sms with Paid Memberships Pro Membership Checkout.
/*
Send a short email with every purchase.
*/
function my_pmpro_checkout_notifications($user_id, $order)
{
global $wpdb;
//email address to send to - for sms/text message, see http://www.emailtextmessages.com/ for your carrier's format
$email = "4444444444@vtext.com, 5555555555@vtext.com";
//only send for levels 1 and 2 - remove lines 12 to 14 to include all levels
$notification_levels = array(1,2);
if(!in_array($order->membership_id, $notification_levels))
return;
//get user info
$user = get_userdata($user_id);
//get level info
$level = pmpro_getLevel($order->membership_id);
//get total order value for today
$today = $wpdb->get_var("SELECT SUM(total) FROM $wpdb->pmpro_membership_orders WHERE status NOT IN('refunded', 'review', 'token', 'error') AND timestamp >= '" . date("Y-m-d", current_time('timestamp')) . "' AND gateway_environment = '" . esc_sql(pmpro_getOption('gateway_environment')) . "' ");
//build message
$subject = "Checkout: " . $level->name;
$message = $user->display_name . " (" . $user->user_email . "). $" . $order->total . " of $" . $today . " today. ";
//sweeten it up
$phrases = array(
"Nice job!",
"Way to go!",
"Keep it up!",
"Alright!",
"Sweet!",
"Awesome!",
"Woah!",
"Nice!",
"Congrats!",
"Yes!",
);
$message .= $phrases[array_rand($phrases)];
//send it
if(class_exists('wpMandrill'))
{
$message = array(
'html'=>$message,
'text'=>$message,
'subject'=>$subject, //$subject,
'to'=>$email,
);
wpMandrill::sendEmail($message, "", "", false, false);
//wpMandrill::wp_mail_native($email, $subject, $message);
}
else
wp_mail($email, $subject, $message);
}
add_action('pmpro_after_checkout', 'my_pmpro_checkout_notifications', 10, 2);
@laurenhagan0306
Copy link

This recipe is included in the blog post on "Track Membership Signups and Stats on a Mobile Device" at Paid Memberships Pro here: https://www.paidmembershipspro.com/track-membership-signups-stats-mobile-device/

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