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
13 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Keiran
Keiran
2 years 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 2 years ago by Keiran
Kitti
Kitti
2 years ago

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

Jacob
Jacob
2 years 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
2 years 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 years ago

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

Chris
Chris
2 years ago

Did you ever get that plugin created to do this? I'd love to just redirect to a new page rather than throw a modal, if at all possible.

Andreas
Andreas
1 year ago

Would also love to the see the plugin. One big feautre for use would be to ask the reason for cancelation. Like price, don't need it anymore, ... And safe the results somewhere (best including emails/UserID/ ordernumber) or something like that.

Lena
Lena
1 year ago

Hello there,
we just tried to add the snippet on our WP site (via code snippets). But the pop up is not appearing when clicking the cancel button. Any idea what could be the problem here?

Sam
Sam
1 year ago

This snippet works perfectly. Thank you so much James.

John Doe
John Doe
11 months ago

This doesn't appear to work anymore. Are you able to confirm? Thanks for your help

Article By
James LePage
Contributors/Editors
notloggedin
James LePage is the founder of Isotropic, a WordPress education company and digital agency. He is also the founder of CodeWP.ai, a venture backed startup bringing AI to WordPress creators.
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