• Resolved wpbetsy

    (@wpbetsy)


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

    That means membership by role.

Viewing 14 replies - 16 through 29 (of 29 total)
  • Thread Starter wpbetsy

    (@wpbetsy)

    However, the function.php shows below codes only. I didn’t see tag ” ?> ”.

    <?php
    /**
    * Online Shop functions and definitions.
    *
    * @link https://developer.www.ads-software.com/themes/basics/theme-functions/
    *
    * @package Acme Themes
    * @subpackage Online Shop
    */

    /**
    * require int.
    */
    require_once trailingslashit( get_template_directory() ).’acmethemes/init.php’;

    Hi @wpbetsy

    Please add the code snippet after the last line in the functions.php file.

    Thread Starter wpbetsy

    (@wpbetsy)

    Who deleted my post here?

    I need to post again.

    What I see in the function.php file is below. I didn’t see any tag ” ?> ” for adding the code. Where should I add it?

    <?php
    /**
    * Online Shop functions and definitions.
    *
    * @link https://developer.www.ads-software.com/themes/basics/theme-functions/
    *
    * @package Acme Themes
    * @subpackage Online Shop
    */

    /**
    * require int.
    */
    require_once trailingslashit( get_template_directory() ).’acmethemes/init.php’;

    Thread Starter wpbetsy

    (@wpbetsy)

    who deleted my post? I have to repost again.

    I only see below code at function.php, no tag ” ?> ”, where should I put the code?

    <?php
    /**
    * Online Shop functions and definitions.
    *
    * @link https://developer.www.ads-software.com/themes/basics/theme-functions/
    *
    * @package Acme Themes
    * @subpackage Online Shop
    */

    /**
    * require int.
    */
    require_once trailingslashit( get_template_directory() ).’acmethemes/init.php’;

    Thread Starter wpbetsy

    (@wpbetsy)

    That means just after “require_once trailingslashit( get_template_directory() ).’acmethemes/init.php’;”?

    Thread Starter wpbetsy

    (@wpbetsy)

    But what do I need to edit below? Or after adding below, related function will appear at admin so that I can set the role with product purchased at admin panel?

    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)

    after putting the code on, our site down!

    Thread Starter wpbetsy

    (@wpbetsy)

    PHP Fatal error: Call to undefined function trailingslashit() in /home/XXXX/public_html/lb/wp-includes/functions.php on line 14

    How to fix please?

    Hi @wpbetsy

    This error seems not related to the code snippet. Please create a support ticket here, so we can help you to fix this in your site.

    Thread Starter wpbetsy

    (@wpbetsy)

    It’s fixed.

    But what do I need to edit below? Or after adding below, related function will appear at admin so that I can set the role with product purchased at admin panel? Can you add this in your plugin actually? I am afraid that my site will be down again.

    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;
    }

    Hi @wpbetsy

    Currently there is no plan for adding this with plugin. Please create a support ticket here, if need any help on configuring this in the website.

    Thread Starter wpbetsy

    (@wpbetsy)

    Could you please simply tell where do need to edit and place the code here? I don’t want to open so many accounts to avoid chaos.

    This might be user to other users as well.

    Hi @wpbetsy

    Please add the code snippet after the last line in the functions.php file.

    ie:- require_once trailingslashit( get_template_directory() ).’acmethemes/init.php’;

    you need to edit the “mycustomrole” part, add your role there

    $role = ‘mycustomrole’; // string $role = Role name

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