Home Support General HivePress How to check if user is a vendor

How to check if user is a vendor

  • Author
    Posts
  • rafaljosko

    how can i check if user is vendor?

    I would like to display two buttons in the menu.

    if user is a vendor, show standard button “add listing”

    else

    display become vendor – and redirect to the page /register-vendor.

    hivepress/listing/submit/listing-submit-link.php

    ihor developer

    The easiest way is checking the user role, HivePress assigns a Contributor role to vendors while regular users have the Subscriber role. You can add conditional menu items using this plugin https://wordpress.org/plugins/nav-menu-roles/

    rafaljosko

    Hey,
    i have problem – my all user have subscriber role, not contributor

    rafaljosko

    For me, the role of contributor does not change – maybe you should consider creating your own role – Vendor or company ? but when the user completes the form on the / register-vendor page – he has the status of subscriber – how can I check if he has completed this form – is there any option? It has to be, because you recognize it and by clicking add listing, I don’t have to fill out the form anymore.

    ihor developer

    Thanks for reporting this, it seems to be a bug – it occurs with direct vendor registration only. If you add at least 1 listing the Contributor role will be set automatically. Will be fixed in the next HivePress update.

    rafaljosko

    Hi,
    Unfortunately I added an lissting and it doesn’t change to contributor – but is it a bad idea to use native wordpress roles? – in the role of contributor, I have already added people who contribute to this portal with me. Isn’t it easier to create your own role?

    ihor developer

    There’s no need for a custom role yet, since vendors are just regular users with a linked vendor ID, but thanks – I’ll check if there’s a better way for marking vendor accounts. If you’re familiar with PHP please try adding a custom role or some meta key when a vendor is registered, you can do this via the “hivepress/v1/models/vendor/update” hook (checking the user role on every vendor profile update).

    rafaljosko

    I change this element in my template
    hivepress/listing/submit/listing-submit-link.php

    Is there any simpler method to check if user is vendor?

    <?php
    // Exit if accessed directly.
    defined( 'ABSPATH' ) || exit;
    
    if ( get_option( 'hp_listing_enable_submission' ) ) :
    $user_id = get_current_user_id(); //
    $post_type = 'hp_vendor'; //
    $posts = count_user_posts( $user_id, $post_type ); //count post
    if( $posts < 1 ):
    
        ?>
            <button type="button" class="hp-menu__item hp-menu__item--listing-submit button button--secondary" data-component="link" data-url="<?php echo esc_url( hivepress()->router->get_url( 'vendor_register_page' ) ); ?>"><i class="hp-icon fas fa-plus"></i><span><?php echo esc_html( hivepress()->translator->get_string( 'add_vendor' ) ); ?></span></button>
        <?php else: ?>
    	    <button type="button" class="hp-menu__item hp-menu__item--listing-submit button button--secondary" data-component="link" data-url="<?php echo esc_url( hivepress()->router->get_url( 'listing_submit_page' ) ); ?>"><i class="hp-icon fas fa-plus"></i><span><?php echo esc_html( hivepress()->translator->get_string( 'add_listing' ) ); ?></span></button>
    	<?php
        endif;
    endif;
    DiegoMora

    Hello, in my case, when a user registers he enters as a subscriber and when publishing avios he can choose to pay or simple, but then he becomes a collaborator and no longer gives him the option to pay a notice when publishing it, that is the problem they have ? how can I solve it?

    DiegoMora

    rafaljosko if you enter users in wordpress you will see the users which category they have

    ihor developer

    @rafaljosko Seems to be ok, I also recommend checking if the user is logged in to avoid extra queries:

    if(is_user_logged_in() && count_user_posts( get_current_user_id(), 'hp_vendor )) {
        // something for vendors here
    } else {
        // something for other users
    }


    @DiegoMora
    Sorry, this is not related to user roles, I replied in the other topic you created.

    Vishan

    @Ihor,
    Is there sign-in link(not modal) which you can add to your own menu using Nav Menu Roles Plugin?

    Thanks
    Vishan

    ihor developer

    There’s no such page by default, but you can create a custom page and insert the User Login Form to its content, then you can add a link to this page anywhere.

    berryinteresting

    How can I have the user login form not show as a modal pop up, but as a separate page. Is there a shortcode? I would like to use Divi Builder.

    ihor developer

    Sure, you can create a custom page for this and add the User Login Form block, or this shortcode:

    [hivepress_user_login_form]

    Please note that the header link will still open the modal form, and some extensions may still open it (e.g. when a non-registered user clicks the Favorite/Message icon).

Viewing 15 posts - 1 through 15 (of 15 total)

You must be logged in to reply to this topic.