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?