Skip to:

Assign member type based on user meta

  • had_hc


    Hi all, I’m trying to automatically assign users to specific member types (seller & supplier) based on each user’s meta (reseller & supplier) that i made. the website i’m developing is using wc vendors pro + woocommerce. Here’s some lines i wrote based something i found here.

    function using_mt_register_member_types() {
        bp_register_member_type( 'seller', array(
            'labels' => array(
                'name'          => __( 'Seller', 'using-mt' ),
                'singular_name' => __( 'Sellers', 'using-mt' ),
            'has_directory' => 'sellers'
        ) );
        bp_register_member_type( 'supplier', array(
            'labels' => array(
                'name'          => __( 'Supplier', 'using-mt' ),
                'singular_name' => __( 'Suppliers', 'using-mt' ),
            'has_directory' => 'suppliers'
        ) );
    add_action( 'bp_init', 'using_mt_register_member_types' );
    function assign_member_type ($user_id, $member_type) {
        $the_id = bp_displayed_user_id();
        $vendor_type = get_user_meta($the_id , '_wcv_custom_settings_vendortype', true );
        $wp_user_object = new WP_User($user_id);
        if($vendor_type == 'designer')
            bp_set_member_type( $user_id, 'seller' );
    add_action( 'bp_init', 'assign_member_type' );

    Member types seller & supplier is created with no problem, but I will get error with the lines I try to automatically assign the members based on their meta. Can anybody help me with this please? Am I onto something here or I’m totally out here? I’m not really good at programming to be honest, just learning as I go (mostly by cut & paste).
    Thanks in advance!

Viewing 1 replies (of 1 total)

  • shanebp


    Currently, you are using the bp_init hook to set the member type.
    That won’t work because you are getting the member id from bp_displayed_user_id() which is only available on profile pages. And that’s why you get an error.
    And even if it worked – it’s very bad to set a member type on every page load.

    The example you linked to uses a specific hook to call the function that sets the member type.
    You need to find or create a hook for your situation – probably from wherever the _wcv_custom_settings_vendortype field is set.
    And then use the same approach as used in the example you linked to.

Viewing 1 replies (of 1 total)
  • The topic ‘Assign member type based on user meta’ is closed to new replies.
Skip to toolbar