• Resolved compito

    (@compito)


    Hi,
    I’m developing a directory site with WPGeoDirectory, and we need an easy way to assign a custom role to users after they have bought a listing package.
    (may be a good idea to create an addon for that?)

    So my question is how to do it programmatically. We’ll use this to get package_id:
    add_action( ‘geodir_pricing_complete_package_post_updated’, function( $post_id, $package_id )

    And when we know what package they have bought we want to assign a role to them, probably something like this:

    switch($package_id) {
    case 1 || 2:
    //add current user to base member role
    break;
    case 3 || 4:
    //add current user to premium member role, etc.
    break;
    }

    So, how do we do that? I can’t find a function to do that, if I haven’t missed something of course…

    Thanks a bunch,
    Damir

    • This topic was modified 3 years, 5 months ago by compito. Reason: Link added
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Caseproof

    (@caseproof)

    Hi Damir,

    To add role to current user you can use this code snippet:

    $user = wp_get_current_user();
    $user->add_role('custom_role'); // Replace this with your custom role

    Hopefully, that helps.

    Thread Starter compito

    (@compito)

    Thanks, that works just fine!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Programmatically add role to users’ is closed to new replies.