isotropic-2022
Share
Blog
Search
Menu

Adding A Confirmation To The WooCommerce Subscription Cancel Button

By James LePage
 on May 26, 2021
Last modified on January 6th, 2022

Adding A Confirmation To The WooCommerce Subscription Cancel Button

By James LePage
 on May 26, 2021
Last modified on January 6th, 2022

This article will show you how to add a cancellation confirmation button to WooCommerce Subscriptions. WooCommerce Subscriptions is a great way to offer subscription based products on a WordPress website, but if a user goes to cancel their subscription, this happens instantly. When cancelling, many users don't understand that this is an irreversible action, and after the pending cancellation., their data is removed from the website. What that means is that they will need to resubscribe to a subscription if they ever want to receive it in the future. If prices change, they won't be grandfathered into the previous subscriptions price.

To clarify, the standard behavior of cancellation in WooCommerce Subscriptions is this. The customer navigates to the my account dashboard, goes to the individual subscription, clicks cancel, and it is immediately cancelled.

This behavior isn't great, especially because there is a suspend feature that places the subscription on hold. This is very similar to canceling a subscription, except when you suspend it, all data remains in place, and the customer can reactivate the subscription at any time.

In many situations, suspending a subscription is great for both the consumer and the business. The business retains all the information on the customer, and the customer is incentivized to come back to the subscription when they need it or can afford it again.

To push customers to suspend their subscription instead of canceling, it makes sense to add a confirmation popup to the WooCommerce Subscription cancel button. Ascentia Lee, when somebody clicks on the cancel button under WooCommerce Subscriptions, instead of immediately canceling the subscription, it displays a popup prompting them to suspend it instead. While the customer can then go ahead and click OK, still canceling the subscription, in many cases they abort the cancellation, and decide to suspend.

Installing the following code on your WordPress website will make a JavaScript popup display when clicking on the cancellation button. This shows a quick confirmation message asking if they truly want to cancel, and if they would consider suspending the subscription instead. If they click OK, the cancellation goes through. If they click cancel, the cancellation does not go through and they are able to click this is spend button on the WooCommerce Subscriptions account dashboard.

Installing this code is very easy, you can add it to your functions.php file, by using code snippets, where by using Advanced Scripts (our review). Advanced Scripts is our recommended method of installing any and all code snippets on a WordPress website as it makes it very easy to do so. Simply copy and paste this into a new Advanced Scripts entry, select PHP, insert it into the WP-head and test out the behavior on the front end of your website.

add_action( 'woocommerce_after_my_account', 'iso_after_my_account' ); add_action( 'woocommerce_subscription_details_after_subscription_table', 'iso_after_my_account' ); function iso_after_my_account() { echo '<script> jQuery(document).ready(function($) { $("td.subscription-actions a.cancel, table.shop_table.subscription_details a.cancel").on("click", function(e) { var confirmCancel = confirm("Are you sure you want to cancel this subscription? This action is not reversible. Instead, consider suspending, which pauses payments indefinitely, but allows you to resume at your current price.") if (!confirmCancel) { e.preventDefault() } }) }) </script>'; }

After installation, when clicking cancel, a confirmation message will pop up, prompting a user to suspend their WooCommerce Subscription instead of cancel it.

Subscribe & Share
If you liked this content, subscribe for our monthly roundup of WordPress news, website inspiration, exclusive deals and interesting articles.
Unsubscribe at any time. We do not spam and will never sell or share your email.
Subscribe
Notify of
guest
8 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Keiran
Keiran
3 months ago

Is it possible to add a pop-up cancellation form here or a shortcode to a form rather than just a message?

Last edited 3 months ago by Keiran
Kitti
Kitti
2 months ago

Hi James! Thank you! Exactly what I need πŸ™‚ Is it possible to also include a vimeo video in the popup?

Jacob
Jacob
25 days ago
Reply to  James LePage

Hi James, I'm looking forward to a plugin as you've described. Is there an email list I can subscribe to for updates?

jacob
jacob
24 days ago
Reply to  James LePage

One functionality that would be quite complex but also valuable is a way to provide a discounted rate to a user who is in the cancellation process, to see if a lower cost will keep them active. My initial thought was it could be a visible coupon code but ideally would apply it to their subscription automatically.

Julien
Julien
2 months ago

Hello
When i choose "cancel" in popup, the subscription is still canceled.

Article By
James LePage
Contributors/Editors
notloggedin
James LePage is the founder of Isotropic Design, a digital agency that builds WordPress websites. I read, write and design constantly!
We're looking for new authors. Explore Isotropic Jobs.
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram