Forum Replies Created

Viewing 15 replies - 1 through 15 (of 26 total)
  • Thread Starter carloz san

    (@wajaraja)

    Hi, thanks for your reply. After I used the VPN I was able to access normally. The concluding question, is the use of this VPN mandatory?

    Thanks

    Thread Starter carloz san

    (@wajaraja)

    hi, why can’t i access this site? Is there something wrong?

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Thanks for the quick reply.

    I’ve changed everything from 6 to 9999.

    However it doesn’t work (when I enable all three codes at the same time).

    However it works fine when only 1 code is enabled.

    Thank You

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Thank you for your reply.

    I answer starting with question :

    2. As for the product agent and partner, it works on my end. Could you please check this issue after fixing issue #1? Here’s my test :

    Sorry, I don’t understand this point.
    Can you explain more simply and in detail?

    ===============================================

    3. Do you want to retrieve the $regno value of the current viewing profile or the currently logged-in user?

    From the current view.

    But these 2 days I tried to make it like this:

    add_filter( 'um_profile_tabs', 'um_my_product_add_tab', 1000 );
    function um_my_product_add_tab( $tabs ) {
        $tabs[ 'my_product' ] = array(
            'name'   => 'My Product',
            'icon'   => 'um-faicon-list-ul',
            'custom' => true
        );
    
        UM()->options()->options[ 'profile_tab_' . 'my_product' ] = true;
    
        return $tabs;
    }
    
    add_action( 'um_profile_content_my_product_default', 'um_profile_content_my_product_default' );
    function um_profile_content_my_product_default( $args ) {
    	
    		$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
    					
    		$actual_link = (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? "https" : "http") . "://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    		$url=$actual_link;
    		$lastSegment = basename(parse_url($url, PHP_URL_PATH));
    		$name = mb_strcut(($lastSegment),0,30);
    		
    		$args = array( 'post_type' => 'product', 'post_status' => 'publish', 
    			'posts_per_page' => -1,
    			'pa_agent' =>$name		 
    					 );
    		
    			$products = new WP_Query( $args );
    			$count = $products->found_posts;
    		
    		if($count>2){
    			
    		echo do_shortcode ('[products columns="2" attribute="pa_agent" terms="('.$name.')" orderby="rand" paginate="true"]');
    		}
    		else{
    			echo '<p>Cooming Soon</p>';
    		}
    	}

    For now it works as I expected.
    But I’m not sure if I’m on the right path?
    If there’s anything you need to correct, I’d be happy to accept it.

    ========================================================

    1. I just noticed that you’re declaring the new tabs with a priority number 1000. And then you’re unsetting the tabs with a priority 6. Please try changing the unsetting function’s priority to 9999. Let’s see if this is causing the issue .

    This is the latest code I had until this answer was posted :

    add_filter( 'um_profile_tabs', 'um_unit_promo_add_tab', 1000 );
    function um_unit_promo_add_tab( $tabs ) {
        $tabs[ 'unit_promo' ] = array(
            'name'   => 'Unit Promo',
            'icon'   => 'um-faicon-list-ul',
            'custom' => true
        );
    
        UM()->options()->options[ 'profile_tab_' . 'unit_promo' ] = true;
    
        return $tabs;
    }
    
    add_action( 'um_profile_content_unit_promo_default', 'um_profile_content_unit_promo_default' );
    function um_profile_content_unit_promo_default( $args ) {
    	echo do_shortcode('[products columns="2" orderby="rand" per_page="8" paginate="true"]');
    
    }

    Then I duplicated it according to the number of tabs I currently need, namely, 9 custom tabs by replacing certain parts as in the code in point 3.(all priorty number 1000)

    The code in point 2 on the previous question can indeed be an alternative.

    However, I have a condition where certain tabs can be seen by anyone (by accessing the direct url address)
    but exclude urls from certain roles.
    So for 2 days I tried to make it like this :

    #HIDE TAB PROMO#

    add_filter( 'um_user_profile_tabs', 'um_hide_tabs', 9999, 1 );
    function um_hide_tabs( $tabs ){
    	if( in_array( um_user('role'), ["um_agent","subscriber","customer"] )  && is_page('profile')){
            unset( $tabs['promotion'] );
    		return $tabs;
    	}
    	$user_id = get_current_user_id();
        um_fetch_user( $user_id );
        if( in_array( um_user('role'), ["um_agent","subscriber","customer","partner" ] )){
            unset( $tabs['promotion'] );
        	}	
        return $tabs;	
    	}

    The code seems to work.

    Under conditions:

    1. Partner roles when not logged in > “Promotion Tab” is shown

    2. Partner roles on login > “Promotion Tab” hidden

    3. The “Promotion Tab” is hidden from all roles other than partners when either the user condition is logged in or not.

    It’s like I want.

    However I have many tabs with different conditions and that has to be adjusted too.

    Finally I duplicated the code above and added it to a new file, and the code looks like this:

    #HIDE TAB UNIT PROMO#

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_tabs', 6, 1 );
    function um_unit_promo_tabs( $tabs ){
    //Hide Unit Promo Tabs from Agents when not logged in
    if( in_array( um_user('role'), ["um_agent"] )  && is_page('profile')){
        unset( $tabs['unit_promo'] );
        return $tabs;
    }
    
    $user_id = get_current_user_id();
    um_fetch_user( $user_id );
    if( in_array( um_user('role'), ["um_agent"] )){
        unset( $tabs['unit_promo'] );
        }   
    return $tabs;   
    }

    And

    #HIDE TAB UNIT RECOMMENDATION#

    add_filter( 'um_user_profile_tabs', 'um_unit_rekomendasi_tabs', 6, 1 );
    function um_unit_recommendation_tabs( $tabs ){
    //Hide unit_recommendation Tabs from Subscribers, Customers, Partner when not logged in
    if( in_array( um_user('role'), ["partner","subscriber","customer" ] )  && is_page('profile')){
        unset( $tabs['unit_recommendation'] );
        return $tabs;
    }
    
    $user_id = get_current_user_id();
    um_fetch_user( $user_id );
    if( in_array( um_user('role'), ["subscriber","customer","partner" ] )){
        unset( $tabs['unit_recommendation'] );
        }   
    return $tabs;   
    }

    If only activate the code #TAB PROMO > Display tabs looks fine.

    But if I also activate #TAB UNIT PROMO and #TAB UNIT RECOMMENDATION this tab display is not what it should be.

    Can you help see this error and how I should refine the code so that I still get what I want?

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    There are 2 things I want to say.

    1. Above the code could not be saved due to an error.

    But I’m trying to fix it to be like this (please correct if I wrong).

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_show_tabs', 6, 1 );
    function um_unit_promo_show_tabs( $tabs ){
        echo "<script>console.log(".json_encode( um_user('role') ) .");</script>";
        return $tabs;
    }

    Then I logged in as agent and did:

    inspect element > console > and there is an “um_agent” role displayed there (Link).

    2. On the back end, I have several roles including partner and agent.

    Partners and agents have their own products.

    For that reason I want this ‘unit_promo’ tab to be hidden from “agent url” because “agent” has its own product.(say ‘unit_promo_agent’ tab.

    Finally I try modified the code like the following.

    add_filter( 'um_profile_tabs', 'um_lis_unit_add_tab', 1000 );
    function um_lis_unit_add_tab( $tabs ) {
        $tabs[ 'lis_unit' ] = array(
            'name'   => 'Unit Promo',
            'icon'   => 'um-icon-ios-videocam',
            'custom' => true
        );
    
        UM()->options()->options[ 'profile_tab_' . 'lis_unit' ] = true;
    
        return $tabs;
    }
    
    add_action( 'um_profile_content_lis_unit_default', 'um_profile_content_lis_unit_default' );
    function um_profile_content_lis_unit_default( $args ) {
    	if( "um_agent" == um_user('role')) {
    		$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
    		
    		echo '<p>Show Product Agent</p>';
    		//unset ($tabs['lis_unit'] ); i try to unset but not working -- still show label
                    //return ($tabs);
    	}
    	else{
    		echo '<p>Show Product Partner</p>';
    	}
    }

    The result is the same as I wanted although currently i still testing it under different conditions.

    My question, is it possible to rename the tab depending on the role?

    Example :

    Partner > Promo Unit

    Agent > My products.

    ===##===

    And how to fill attribute terms on woocommerce shortcode based on the value of the “regno” meta key owned by agent’s dinamically?

    Example :
    Original code :

    [products columns="3" attribute="regno" terms="ABC123" orderby="date"]

    Customization code(the one think by me) :

    [products columns="3" attribute="regno" terms="$regno" orderby="date"]

    OR

    if( "um_agent" == um_user('role')) {
    		$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
    		//echo '<p>Show Product Agent</p>'; THIS REPLACE TO
    
    global $current_user;	
    
    $regno = um_user('regno');
    echo do_shortcode(' [products columns="3" attribute="regno" terms="$regno" orderby="date"]');
    	}
    }

    On the other hand, in each product I have added an attribute labeled regno and its value is the value of the meta key “regno” owned by the agent, in this example it is “ABC123”.

    If it works, I think it will solve the problem.

    Thank you

    • This reply was modified 3 years, 3 months ago by carloz san.
    Thread Starter carloz san

    (@wajaraja)

    Okay, I’ll try it tomorrow and tell you. Local time now is 01.40 am

    Thank you so much

    • This reply was modified 3 years, 3 months ago by carloz san.
    • This reply was modified 3 years, 3 months ago by carloz san.
    Thread Starter carloz san

    (@wajaraja)

    Can you please confirm that you want to hide the Unit Promo tab for the currently logged-in users who are Agents and those who are not logged in?

    Yes, i want to hide the Unit Promo tab for the currently logged-in users who are Agents and those who are not logged in (only url agent).

    Example :
    mysite.com/profile/partnername => roles partner => show

    mysite.com/profile/customername => roles customer => show

    mysite.com/profile/agentname => roles agent => hide

    =========###=========

    Do you have a caching plugin or server cache module? If so, please try disabling them and then test if this is causing the issue?

    Yes, I’m using the wp-supxx-xxxxx plugin. Now, i’ve disabled and tested using (alternately) all the code that’s been provided.

    But still didn’t work.

    =========###=========

    I’m totally newbi to this.

    But if I can give an opinion, of all the code shared I feel the closest code is this one by slightly changing :
    if( ! is_user_logged_in() || "agent" == um_user('role') ) {
    to
    if( ! is_user_logged_in() && "agent" == um_user('role') ) {

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_show_tabs', 6, 1 );
    function um_unit_promo_show_tabs( $tabs ){
         	$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
            
        if( !is_user_logged_in() && "um_agent" == um_user('role')) {
    	unset( $tabs['unit_promo'] );
            return $tabs;
        }
        
        if( "um_agent" == um_user('role') ){
            unset( $tabs['unit_promo'] );
        }
    
        return $tabs;
    }

    This code displays a ‘unit_promo’ tab on the urls of all roles, even though the target excludes urls with the agent role.

    But this code is better because it doesn’t omit existing rules.

    And I still don’t understand why it doesn’t work.

    I hope to find the code that saves my days.

    Thank you

    Thread Starter carloz san

    (@wajaraja)

    Unfortunately it still doesn’t work.

    There are a few things I want to say.

    1. When the user conditions enter (partner, subscriber, agent, customer) all tab conditions work properly.

    Example :
    agent cannot see certain tabs owned by partner.

    2. When the user logout (and uses the last code/above), this is like breaking the rules that have been set previously, for example the unit_promo tab is missing and the current display is “This user has not added any information to their profile yet”

    3. However, the conditions are different when I deactivate the code, when the user exits the display shows the partner’s ‘unit_promo’ tab.

    This ‘unit_promo’ tab becomes visible to all roles

    (I checked via direct url address > mysite.com/profile/username1 =>agent, etc)

    4. When I login using the agent role, the ‘unit_promo’ tab is not visible and this is correct.

    5. The last only think how to make the ‘unit_promo’ tab not appear on the url agent when the anyone accessed via a direct url.

    Thank you very much

    Thread Starter carloz san

    (@wajaraja)

    Hi, sorry I just replied to the message.

    1. I want to say that the code below has worked well, thank you

    if( in_array( um_user('role'), ["partner","subscriber","customer" ] ) ){
        unset( $tabs['uo_learndash_certificates'] );
    }

    2. I regret not being careful. The correct slug for “agent” is “um_agent”.
    But even though I have fixed it, it doesn’t change the situation.

    3. I have 5 codes to add custom tabs.
    All five tabs look fine so far.

    The problem is only on the ‘unit_promo’ tab as described previously.

    Here’s the code :

    add_filter( 'um_profile_tabs', 'um_mycustomtab_add_tab', 1000 );
    function um_mycustomtab_add_tab( $tabs ) {
    
    	$tabs['note'] = array(
    		'name'            => 'Note',
    		'icon'            => 'um-faicon-book',
    		'custom'          => true
    	);
    
    	if ( !isset( UM()->options()->options['profile_tab_' . 'note'] ) ) {
    		UM()->options()->update( 'profile_tab_' . 'note', true );
    	}
    
    	$tabs['unit_promo'] = array(
    		'name'            => 'Unit Promo',
    		'icon'            => 'um-faicon-certificate',
    		'custom'          => true
    	);
    
    	if ( !isset( UM()->options()->options['profile_tab_' . 'unit_promo'] ) ) {
    		UM()->options()->update( 'profile_tab_' . 'unit_promo', true );
    	}
    
    	return $tabs;
    }
    
    add_action( 'um_profile_content_note', 'um_profile_content_note' );
    
    function um_profile_content_note() {
    	
    	echo '<p>this content for partner</p>';
    	
    }
      
    
    add_action( 'um_profile_content_unit_promo', 'um_profile_content_unit_promo' );
    function um_profile_content_unit_promo( $args ) {
    	
    	echo do_shortcode('[products columns="2" orderby="rand" per_page="8" paginate="true"]');
    
    }
    

    Please also check the new code that has been added:

    1) Not work

    add_filter( 'um_user_profile_tabs', 'um_unit_promo_show_tabs', 6, 1 );
    function um_unit_promo_show_tabs( $tabs ){
         	$user_id = get_current_user_id();
        	um_fetch_user( $user_id );
            
        if( !is_user_logged_in() || "um_agent" == um_user('role')) {
    	unset( $tabs['unit_promo'] );
            return $tabs;
        }
        
        if( "um_agent" == um_user('role') ){
            unset( $tabs['unit_promo'] );
        }
    
        return $tabs;
    }

    2) Work

    add_filter( 'um_user_profile_tabs', 'um_note_show_tabs', 6, 1 );
    function um_note_show_tabs( $tabs ){
    
    	
    	
    if( !is_user_logged_in()) {
    unset( $tabs['note'] );
    return $tabs;
    }
    
    $user_id = get_current_user_id();
    um_fetch_user( $user_id );
    
    if( in_array( um_user('role'), ["customer","subscriber","um_agent","partner" ] ) ){	
    unset( $tabs['note'] );
    }
    
    return $tabs;
    }

    Thank you for reviewing and helping me.

    Thread Starter carloz san

    (@wajaraja)

    Yes, the code makes the unit tab hidden from all roles and the user is not logged in.

    However, the code also makes the “about” tab appear (even though in the settings is set only the admin)

    Thread Starter carloz san

    (@wajaraja)

    Yes, correct…

    Thread Starter carloz san

    (@wajaraja)

    I’m not currently logged in as any role.

    I just use the direct url address on the browser to check the tabs on each role.

    Example :

    mysite.com/profile/username1 (agent)

    mysite.com/profile/username2 (partner)

    mysite.com/profile/username3 (subscriber)

    Thread Starter carloz san

    (@wajaraja)

    I’ve checked in every section and I’m sure like the slug and tab names are correct.

    but code still not working…

    Thread Starter carloz san

    (@wajaraja)

    Hi @champsupertramp

    Unfortunately your code (1) has not worked for me.

    Is there any other way?

    Thread Starter carloz san

    (@wajaraja)

    1. Yes, I sure the role/slug ID is agent

    2. Please wait a moment, I will try it.

Viewing 15 replies - 1 through 15 (of 26 total)