Send Easy Digital Downloads Subscription Cancellation Email to Admin

This tutorial will show you how to have an automated email sent to a site administrator upon the cancellation of an Easy Digital Downloads (EDD) Recurring Payments Subscription. Note that this assumes you are using Easy Digital Downloads with the Recurring Payments extension.

This need came about when I was working on a project that involved a client that had subscription that had a relatively high churn rate. In this specific instance, there were a few small tasks that needed to be performed when a user cancelled their subscription. By default, the admin was not notified of each cancellation, so it was a bit laborious to keep checking cancelled subscriptions to ensure all proper steps were taken for each cancellation.

The snippet below will send an email to the email address you choose when a subscription is cancelled. It should be added to the functions.php file.

<?php
//Send admin email when subscription is cancelled
function wd_cancellation_email( $sub_id, $subscription ) {
	$email_to = 'admin@email.com';
	$user_email = $subscription->customer->email;
	$user_name = $subscription->customer->name;
	$subject  = 'EDD Cancellation Email Subject';
	$message  = 'This email confirms that a subsription for ' . $user_name . ' with the email address ' . $user_email . ' has been cancelled.';
	EDD()->emails->send( $email_to, $subject, $message );
}
add_action( 'edd_subscription_cancelled', 'wd_cancellation_email', 10, 4 );

This action runs each time a subscription is cancelled using the edd_subscription_cancelled action. It creates an email and uses the EDD()->emails->send functionality to send out the email based on the parameters you supply.

You’ll want to change the ‘admin@email.com’ to the email address you’d like the cancellation email sent to. You can also customize the $subject and $message as needed. That’s all there is to it!

Comments

  1. eddseo says:

    Hi there, Is it possible with EDD to redirect to a page to confirm unsubscribe? Thanks

    1. Matt Whiteley says:

      Hey! I’m not sure exactly. What would they be unsubscribing from? This tutorial goes over the emails when a subscription is cancelled. I’m not sure that you can “unsubscribe” from a subscription.

Leave a Reply

Your email address will not be published. Required fields are marked *