我正在使用WooCommerce订阅插件,我想停止用户角色的改变只在取消订阅时。
我发现了一个代码片段 此处:
add_filter( 'woocommerce_subscriptions_update_users_role', '__return_false', 100 );
...这停止WooCommerce订阅改变用户的角色。这也将停止购买订阅时的角色变更。
我想要的是停止用户角色的改变。只有在取消订阅时. 这可能吗?
谅谅
你可以尝试使用 woocommerce_subscription_status_cancelled
动作钩 (没有任何保证,因为它没有经过测试),这种方式。
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 );
}
该代码在你的活动子主题(或主题)的function.php文件中,或在任何插件文件中。
参考。订阅状态更改操作
remove_action( 'woocommerce_subscription_status_cancelled', 'wcs_maybe_make_user_inactive_for', 10, 1 );
在你的活动主题function.php中使用这个