Adding A Confirmation To The WooCommerce Subscription Cancel Button

Published: 4 weeks ago

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.

Join Our Newsletter
Here's what you get: A once a week newsletter that contains original content, aggregated posts, WordPress deals, and anything else we think you'd like. We don't spam or sell your email address. Unsub at any time.
Ezoicreport this ad
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
IsoGroup- Web Dev/Design, WordPress and More

Affiliate Disclosure: Some links on this website are affiliate links. We make commissions for purchases made through those links.

We only recommend items/tools that we've personally used and like.

Full Disclosure | FTC Statement

Join Our Newsletter
Over 4,000 Design Lovers and Problem Solvers.

Author

Ezoicreport this ad
A relationship driven website creation company.

Connect

© ISOTROPIC, LLC 2016-2021
linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram