📌  相关文章
📜  woocommerce 订阅自定义用户 rolde - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:42.650000             🧑  作者: Mango

代码示例1
add_action( 'woocommerce_subscription_status_expired', 'change_user_role_on_subscription_expired', 10, 1 );
function change_user_role_on_subscription_expired( $subscription ) {
    // Get WP_User Object from subscription
    $user = new WP_User($subscription->get_user_id());

    if ( in_array('agencia_pro', $user->roles) ) {
        $user->remove_role( 'agencia_pro' );
        $user->add_role( 'agencia' );
    }
    elseif ( in_array('agencia_pro_plus', $user->roles) ) {
        $user->remove_role( 'agencia_pro_plus' );
        $user->add_role( 'agencia' );
    }
    elseif ( in_array('talento_pro', $user->roles) ) {
        $user->remove_role( 'talento_pro' );
        $user->add_role( 'talento' );
    }
    elseif ( in_array('talento_pro_plus', $user->roles) ) {
        $user->remove_role( 'talento_pro_plus' );
        $user->add_role( 'talento' );
    }
}