• Resolved wpbetsy

    (@wpbetsy)


    Can make it assign role automatically according to purchased certain product?

    That means membership by role.

Viewing 15 replies - 1 through 15 (of 29 total)
  • Hi @wpbetsy,

    Currently the plugin is not doing that, however you can do that with help of any of below filters in the plugin..

            $new_membership_data = apply_filters('hf_memberships_new_membership_data', $new_membership_data, array(
                'user_id' => (int) $args['user_id'],
                'product_id' => (int) $args['product_id'],
                'order_id' => (int) $args['order_id'],
                    ));
            do_action('hf_memberships_user_membership_created', $membership_plan, array(
                'user_id' => $args['user_id'],
                'user_membership_id' => $user_membership->get_id(),
                'is_update' => $updating,
            ));
    Thread Starter wpbetsy

    (@wpbetsy)

    Where should I put this on? Only put any one of the above? Are there any differences?

    Do I need to change anything or just place the above code exactly?

    Hi @wpbetsy

    Please contact us via support to help you fix the same.

    Thread Starter wpbetsy

    (@wpbetsy)

    Hi,

    In order to save time, could you please just tell the path to the file and location that I should put on the file? Or it can be done at admin, just simply tell then.

    Thank you!

    Thread Starter wpbetsy

    (@wpbetsy)

    This should be a common question that other users may want to know too.

    Hi @wpbetsy

    You can prepare a code snippet using the filter “hf_memberships_new_membership_data” as we are exposing below details while creating a membership.

     $new_membership_data = apply_filters('hf_memberships_new_membership_data', 
                $new_membership_data, array(
                'user_id' => (int) $args['user_id'],
                'product_id' => (int) $args['product_id'],
                'order_id' => (int) $args['order_id'],
                    ));

    You can put the code snippet in your active theme functions.php

    Thread Starter wpbetsy

    (@wpbetsy)

    Can you update the plugin? make membership by role?

    Thread Starter wpbetsy

    (@wpbetsy)

    as a choice in next version?

    Hi @wpbetsy

    Currently we have no plan for this to include in the plugin. This can be achieved with the help of above filter as you can change to any role while customer joining to any membership plan.

    Thread Starter wpbetsy

    (@wpbetsy)

    Hi,

    Actually, I want both. By purchasing certain product, the user will be assigned a membership (the existing membership plan in your plugin) and a role.

    How to achieve it easily? I am not familiar with codes.

    Hello @wpbetsy

    Please try below code snippet with necessary changes.

    add_filter('hf_memberships_new_membership_data', 'assign_role_after_membership');
    
    function assign_role_after_membership($new_membership_data, $user_id_product_id_order_id) {
    
        $theUser = new WP_User($user_id_product_id_order_id['user_id']);
        
        $role = 'mycustomrole'; // string $role = Role name 
        
        $theUser->add_role($role);
    
        return $new_membership_data;
    }
    Thread Starter wpbetsy

    (@wpbetsy)

    Which row of the function.php should it be placed? What’s the path to locate the function.php on server?

    After adding the code, related function will appear at wordpress backend?

    Hi @wpbetsy

    Please contact us here in our support page to help you fix the code snippet in your site.

    Thread Starter wpbetsy

    (@wpbetsy)

    Hi,

    Can you please just simply help here? I don’t want to open so many accounts which result in chaos.

    Which row of the function.php should it be placed? What’s the path to locate the function.php on server?

    After adding the code, related function will appear at wordpress backend?

    Hi @wpbetsy

    The code snippet can be added to last line of the functions.php just before the tag ” ?> ”

    You can see the functions.php file in the root folder of your active theme ( in child theme if any child theme )

    By adding the code snippet, each member will be added to the custom role you defined in the code snippet.

Viewing 15 replies - 1 through 15 (of 29 total)
  • The topic ‘assign role’ is closed to new replies.