How to Disable the Resubscribe feature in Woocommerce Subscriptions Plugin

This brief guide is aimed at developers familiar with WordPress who are looking to disable the Resubscribe feature in WooCommerce’s very own “Woocommerce Subscriptions” plugin.

Let’s dive right in.

Outline

  1. Solution(s).
  2. Show the Work.

At the time of this writing (2023-07-03), there is no option to turn off the “Resubscribe” functionality. If you’ve come into a scenario where that is becoming problematic (not unheard of – plus, I’m also having this issue), you might be searching for a solution.

…And probably didn’t find anything that helped.

Solution(s).

Well I dug through the code and found two quick solutions that you can drop in your child or custom theme’s functions.php file, a custom plugin, or a mu-plugin drop in. The first solution is my preferred method as it effectively disables the feature:

// This simply says "nobody has the authority to resubscribe a subscription ever"
add_filter( 'wcs_can_user_resubscribe_to_subscription', '__return_false' );

The alternative just removes the button from rendering, but if a customer knew how to mock up the url to do it, or was provided a link, could still purchase the resubscription. This might be a better solution for scenarios where you want to modify or tailor how customers get to “Resubscribe”, but still leave it as a functioning feature:

// This method simply removes action buttons like "reactiveate", "resubscribe", and "cancel" from being rendered.
add_filter( 'wcs_view_subscription_actions', function($subscription_actions){
    if ( !empty($subscription_actions['resubscribe']) ) {
        unset($subscription_actions['resubscribe']);
    }
    return $subscription_actions;
});

Both will remove the “Resubscribe” button from being rendered, but only the wcs_can_user_resubscribe_to_subscription filter denies the resubscribe functionality across the site.

Show the Work.

I’d like to show my work so you can A.) follow along, B.) be more informed in your decisions, and/or C.) trust the process coming to these solutions.

Let’s start in the Subscription Details template where the “Resubscribe” button gets rendered: ./woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/templates/myaccount/subscription-details.php. Inside that file (currently line 78), there’s a function called wcs_get_all_user_actions_for_subscription() who’s job is to get all the “Actions” that are contextually available for that subscription to that user.

We then look at that function’s definition in ./woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/wcs-user-functions.php and see that upon return, it has the second solution’s filter. Here we can remove any of the available options from rendering as an available action. Mind you, this *only* removes the “Resubscribe” button from rendering in the “view subscription” template. Placing a similar button anywhere else will still work!

However, if we’re specifically looking at disabling the “Resubscribe” feature altogether, we see in the middle of the wcs_get_all_user_actions_for_subscription() function, it leverages a function called wcs_can_user_resubscribe_to() – that sound promising! Finding its definitiong in ./woocommerce-subscriptions/vendor/woocommerce/subscriptions-core/includes/wcs-resubscribe-functions.php, we see in its return that it provides another filter wcs_can_user_resubscribe_to_subscription — and ultimately — this is the one I prefer to use.

Using WordPress’s predefined function __return_false for the wcs_can_user_resubscribe_to_subscription filter denies anyone from resubscribing, effectively disabling the feature. Or you could implement your own logic in place of __return_false – another conversation for another time.

Hit me up with any questions, improvements, and/or thoughts you have =]

Cheers,

Ryan

Leave a Reply...

Rohjaynator::1714454107::11014420