• Resolved poco06

    (@poco06)


    Hello,

    I’m using this plugin and I’m very happy with it.
    I just have an issue as I want to affect a member to a specific group inside a hook. Here is my code :

    add_action(‘cred_commerce_after_payment_completed’,’affectation_membre’,10,1);
    function affectation_membre($data)
    {
    $user = new Groups_User( get_current_user_id() );
    $user_id = $user->id;
    $group_id == 2;
    Group_User_Group::create(array( ‘user_id’ => $user_id, ‘group_id’ => $group_id->group_id ) );
    }

    Could you tell me if there is any issue with this code?

    Another point, what if the user is already belonging to the group (is there any new record made in the database or everything is left like it is?).

    Many thanks
    Pat

    http://wordpress.org/plugins/groups/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author itthinx

    (@itthinx)

    Hi,

    You have an equality test instead of an assignment in your code:

    $group_id == 2;

    … is an equality test and should rather be:

    $group_id = 2;

    If the user already belongs, it won’t duplicate entries.

    Plugin Author itthinx

    (@itthinx)

    … and the next line is trying to pull the group_id from an object which isn’t.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Issue on affecting a member to a group’ is closed to new replies.