woocommerce subscriptions custom user rolde

Solutions on MaxInterview for woocommerce subscriptions custom user rolde by the best coders in the world

showing results for - "woocommerce subscriptions custom user rolde"
Lilita
24 Nov 2019
1add_action( 'woocommerce_subscription_status_expired', 'change_user_role_on_subscription_expired', 10, 1 );
2function change_user_role_on_subscription_expired( $subscription ) {
3    // Get WP_User Object from subscription
4    $user = new WP_User($subscription->get_user_id());
5
6    if ( in_array('agencia_pro', $user->roles) ) {
7        $user->remove_role( 'agencia_pro' );
8        $user->add_role( 'agencia' );
9    }
10    elseif ( in_array('agencia_pro_plus', $user->roles) ) {
11        $user->remove_role( 'agencia_pro_plus' );
12        $user->add_role( 'agencia' );
13    }
14    elseif ( in_array('talento_pro', $user->roles) ) {
15        $user->remove_role( 'talento_pro' );
16        $user->add_role( 'talento' );
17    }
18    elseif ( in_array('talento_pro_plus', $user->roles) ) {
19        $user->remove_role( 'talento_pro_plus' );
20        $user->add_role( 'talento' );
21    }
22}