We recently had a customer remove an item from a subscription by going into their account, choosing the subscription and deleting an item. We manage multiple websites for this customer, but one of their sites was recently sold and he no longer needed it supported.
We use WooCommerce Subscriptions to manage subscriptions and it’s a fantastic, robust system. Here’s what the subscription screen looks like (on cinchws.com). It’s very easy to remove an item:
This is great and I’m glad our customers can easily manage their accounts and subscriptions this way. The problem, however, is that removing items in this way doesn’t trigger a notification. Customers with multiple items in a subscription could theoretically remove a few and we’d never be the wiser.
Thankfully, this customer messaged us directly to say that even though he’s canceling a subscription, it wasn’t a cut on our service – the site had simply been sold and he no longer needed support.
Well, imagine my confusion at that email, not having seen a cancelation come in. We searched through Woo orders and subscriptions, but couldn’t find anything about the cancelation…
WooCommerce Subscriptions isn’t able to send notifications for this type of change.
There are notifications for many subscription changes and situations (see them here), but unfortunately, a hook does not exist to send notifications for when a user removes an item from a subscription.
Once we determined that he did actually cancel, I reached out to WooCommerce.com and started a chat. The support agent confirmed a hook doesn’t exist, but thankfully helped figure out a workaround. The breakthrough came when we discovered that a Subscription Note is created when a user does this:
Customer removed “Essential Support for WordPress (url: https://procentive.com)” (Product ID: #30) via the My Account page.
Get Notified
Getting a notification for this type of change is important and should be built into WooCommerce Subscriptions. I’ve added the idea to https://ideas.woocommerce.com, so we’ll see how far that goes. Until then, here’s how we’ve solved it.
Automate Woo
I’m not a huge fan of purchasing a plugin to solve this type of issue, and it’s more than likely possible to do this with a hook, but we needed it done quickly. AutomateWoo is a plugin that was acquired by Automattic and is packed full of features. One of those features is the ability to send an email when a note is left on a subscription. Since the rest of the features look like things we should be doing (Abandoned Cart, Follow up Emails, etc.), we bought in.
Set Up a Notification with AutomateWoo
AutomateWoo uses a ‘workflow’ system to set up different emails and notifications. Once you get the plugin installed, go to AutomateWoo > Workflows and click on Add Workflow. Name the workflow then choose a trigger. I chose ‘Subscription Note Added.’
Adding some relevant text to the ‘Note contains text’ area will make sure it only sends in the right situation. Since I had a note to go on, I chose to add ‘Customer removed.’
The next section, ‘Rules,’ is optional. I skipped this because the trigger seemed relevant enough. These rules will come in handy on other workflows, however:
The ‘Actions’ section is next. This is where you set up the email notification and is fairly straight forward. The list of actions is extensive, but in this case, I chose ‘Send Email.’ Enter the address to send to and a subject. You can also set email headers and preheaters, but I left them blank. You can also choose a template – I went with the default WooCommerce template.
The next section is for the email content. There is a fairly robust list of variables you can use to help construct the content. Since this is a simple notification for ourselves we just added the customer’s name and a link to the subscription order. The order link doesn’t actually work, but there doesn’t appear to be a variable to the user’s subscription, so this is close enough:
And here’s a list of the variables you can use:
We tested the system and it works as advertised. It’s a quick, simple way to get notifications when a user removes an item from a subscription and we’re glad to know its in place. Next step is to explore the rest of what AutomateWoo can do.
Questions?
Leave any questions in the comments below or start a chat!
1 Comment
As an alternative programmatic solution, you can add this function to the functions.php file, which is located in your current theme folder.
/*
* Update Subscription when subscription line item has been removed or restored.
*/
function trigger_wcs_webhook_updated() : void
{
if(
is_user_logged_in()
&& isset($_GET[‘subscription_id’]) && is_numeric($_GET[‘subscription_id’]) && $_GET[‘subscription_id’] >= 1
&&
(
isset($_GET[‘remove_item’]) && is_numeric($_GET[‘remove_item’]) && $_GET[‘remove_item’] >= 1
|| isset($_GET[‘undo_remove_item’]) && is_numeric($_GET[‘undo_remove_item’]) && $_GET[‘undo_remove_item’] >= 1
)
&& isset($_GET[‘_wpnonce’])
&& wp_verify_nonce( $_GET[‘_wpnonce’], $_GET[‘subscription_id’] )
&& wcs_is_subscription( $_GET[‘subscription_id’] )
)
{
$oSubscription = wcs_get_subscription($_GET[‘subscription_id’]);
WCS_Webhooks::add_subscription_updated_callback($oSubscription);
}
}
add_action(‘wcs_user_readded_item’, ‘trigger_wcs_webhook_updated’, 11 );
add_action(‘wcs_user_removed_item’, ‘trigger_wcs_webhook_updated’, 11 );
Comments are closed.