Show certain parts of Listing depending on user role

This topic contains 3 replies, has 2 voices, and was last updated by  Kor 7 years, 9 months ago.

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket
  • Author
    Posts
  • #232989

    macmizer
    Expired Member
    Post count: 22

    We are using GeoDirectory on a site wherein the listings will display discounts for the members that sign up for the site. We have two separate roles that are assigned to members. One role we will called userrole1 and the other user role us userrole2. Each business will pay to have a listing and within that listing we want to set it up so that when the business owner enters the discounts they will do so in a typical text field and/or insert an image that is like and ad and on that image it will contain the discount. Here is my issue, userrole1 would or should see the fields/image that perstains to userrole1. Then there are additional fields/image that userrole2 should only see. We need the business owner to be able to show one discount to one member userrole1 and a different discount to userrole2. The members with the role userrole2 should see the fields and image that shows a deeper discount than the members in the userrole1. What the business does not want is for userrole1 to see that userrole2 gets a larger discount. How may we accomplish this?

    #233055

    Kor
    Moderator
    Post count: 16516

    Hi Macmizer,

    This requires custom customization to the theme files which falls outside the scope of what we offer for support. I did a quick Google search and I found out that you’ll need to use “user role editor” plugin to make user roles with the different levels you want, for example, level_0 and level_1 , then use the code below to display the contents according to the levels. Well, I hope this helps.

    
    
    <?php
    if(current_user_can('level_0')) : ?>
    <div class="messages">
    level 0 content
    </div>
    <?php endif; ?>
    
    <?php
    if(current_user_can('level_1')) : ?>
    <div class="messages">
    level 0 content
    </div>
    <?php endif; ?>
    #233103

    macmizer
    Expired Member
    Post count: 22

    Thanks for this reply. I am curious even though this is outside your scope I do appreciate the extra effort. I have to build two more sites for 2 different clients so the more I can do with your product the better. I want to implement the same software for them.

    Question if you have time… Where could I put the sample code you gave below? Keeping in mind that I want to make sure that when we update your plugin or our theme we don’t blow away that custom code.

    I noticed the two sections you pasted below, they are identical. Was that intentional?

    Rob.

    #233113

    Kor
    Moderator
    Post count: 16516

    Hi Macmizer,

    Thanks for your reply. I’ve just discussed this matter with our developer and here’s the code you can use. Apply this code to your functions.php file and it will be shown on the “Add Listing” form under price package section. Please make sure the userrole1 & userrole2 capability is set for user. Use a child theme if you want to keep the changes. Well, let us know how it goes.

    
    
    function geodirectory_before_detail_fields() {
        if ( is_admin() ) {
            return;
        }
        
        if ( current_user_can( 'userrole1' ) ) { 
            ?>
            <div class="geodir_form_row clearfix" id="geodir_userrole1_row">
                <label>User Role 1</label>
                <p></p>
            </div>
            <?php
        }
        
        if ( current_user_can( 'userrole2' ) ) {
            ?>
            <div class="geodir_form_row clearfix" id="geodir_userrole2_row">
                <label>User Role 2</label>
                <p></p>
            </div>
            <?php
        }
    }
    add_action( 'geodir_before_detail_fields' , 'geodirectory_before_detail_fields', 3 ); 
Viewing 4 posts - 1 through 4 (of 4 total)

We have moved to a support ticketing system and our forums are now closed.

Open Support Ticket