【问题标题】:WooCommerce Subscriptions: Remove role on cancelled subscriptionWooCommerce 订阅:删除取消订阅的角色
【发布时间】:2019-07-19 17:53:49
【问题描述】:

当用户购买订阅时,我正在使用第三方插件为用户分配一个角色 - 根据购买的不同,有两种不同的角色(白银、黄金)

但是,如果他们取消订阅,他们将保留该角色。

当他们取消时我不希望他们保留该角色,我如何删除该角色。

【问题讨论】:

    标签: php wordpress woocommerce woocommerce-subscriptions


    【解决方案1】:
    add_action('woocommerce_subscription_status_cancelled', 'wcs_maybe_remove_role', 10, 1);
    
    function wcs_maybe_remove_role($subscription) {
        $user_id = $subscription->get_user_id();
        $user = new WP_User($user_id);
        $user->remove_role('silver');
        $user->remove_role('gold');
    }
    

    【讨论】:

    • 完美。谢谢。
    【解决方案2】:

    对于阅读这篇文章的每个人,此功能已经内置在 WooCommerce/Settings/Subscriptions 下。

    【讨论】:

      猜你喜欢
      • 2021-02-24
      • 1970-01-01
      • 1970-01-01
      • 2019-01-03
      • 1970-01-01
      • 2016-07-12
      • 2017-12-03
      • 2019-07-29
      • 1970-01-01
      相关资源
      最近更新 更多