WooCommerce Subscriptions creates a My Subscriptions section in your customer’s My Account area. This helps them easily manage their subscriptions. They can pause, cancel, upgrade, change payment methods, etc… as needed. If you want to customize the My Subscriptions section, you can modify the template associated with it. You can update the template the same way you override core WooCommerce templates.
Look for the template named my-subscriptions.php
. It’s located under the /myaccount/
folder. To override it in your theme, copy the /templates/myaccount/my-subscriptions.php
file found in the WooCommerce Subscriptions plugin folder to your theme in the location: /woocommerce/myaccount/my-subscriptions.php
. From there, you can follow the process outlined in our developer docs for Template structure & Overriding templates via a theme to modify it.
Adding a confirmation message on the My Account page
↑ Back to topNote: We are unable to provide support for customizations under our Support Policy. If you need to customize a snippet or extend its functionality, we recommend working with a Woo Agency Partner or finding a WooCommerce developer on Codeable.
By default, when a customer clicks the suspend, cancel, or renew button on their My Account page, the action processes immediately without any additional confirmation required from your customer.
If you’d like to add a confirmation message to this process, you can follow a process like the one below to create a template override and add some custom code.
- Copy the
/woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/templates/myaccount/subscription-details.php
template from the plugin folder into your theme’s folder at the location/woocommerce/myaccount/subscription-details.php
. (Learn more about overriding WooCommerce templates). - Find the line used to display the link button for each action. Its HTML is shown below, and it is contained within a table with the class
subscription_details
. - Replace the link text with the new link text included below.
The original link will look like this:
<a href="<?php echo esc_url( $action['url'] ); ?>" class="<?php echo esc_attr( trim( implode( ' ', $classes ) ) ); ?>">
<?php echo esc_html( $action['name'] ); ?>
</a>
To display a confirmation dialogue, change the link markup to this:
<?php if(in_array($key, array('cancel', 'suspend'))) : ?>
<a href="<?php echo esc_url( $action['url'] ); ?>" class="button <?php echo sanitize_html_class( $key ) ?>" onclick="return confirm('<?php printf( __( 'Are you sure you want to %s this subscription?', 'woocommerce-subscriptions' ), esc_html( $action['name'] ) ); ?>');"><?php echo esc_html( $action['name'] ); ?></a>
<?php else: ?>
<a href="<?php echo esc_url( $action['url'] ); ?>" class="button <?php echo sanitize_html_class( $key ) ?>"><?php echo esc_html( $action['name'] ); ?></a>
<?php endif; ?>
With that in place, your customers should see this notice confirming they do want to cancel their subscription. That second confirmation can help reduce any accidental cancelations.