3

I'm using WooCommerce Subscriptions plugin and I would like to stop user role changing only when canceling a subscription.

I found a code snippet here:

add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );

… which Stop WooCommerce Subscriptions Changing a User's Role. This will stop role changing when purchasing a subscription too.

What I would like is to stop user role changing only when canceling a subscription.
Is it possible?

Thanks

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
Aadi
  • 6,959
  • 28
  • 100
  • 145

2 Answers2

0

You could try to use woocommerce_subscription_status_cancelled action hook (without any guaranty as it's untested), this way:

add_action( 'woocommerce_subscription_status_cancelled', 'keep_user_role_unchanged_on_cancelled_status' );
function keep_user_role_unchanged_on_cancelled_status(){
    add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );
}

The Code goes in function.php file of your active child theme (or theme) or also in any plugin file.

Reference: Subscription Status Change Actions

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
0
remove_action( 'woocommerce_subscription_status_cancelled', 'wcs_maybe_make_user_inactive_for', 10, 1 );

Use this in your active theme functions.php

mujuonly
  • 11,370
  • 5
  • 45
  • 75