bbb
February 21, 2023, 4:06pm
1
Hi!
First of all, as always, thank you for the best listing plugin out there!
I read this post about hiding a certain category for specific membership-IDs when submitting a listing. https://community.hivepress.io/t/hide-categories-only-for-a-specific-plan/2330/10
I have two question:
This is based on the membership ID which changes for every user that is granted a membership (on my site I do this manually). Is it possible to use the plan ID? Because the plan is always the same.
Is it possible to do the same thing based on user role ID? This would help me alot.
With best regards,
bb
yevhen
February 22, 2023, 5:44pm
3
The code snippet from the linked topic is based on the membersip plan ID
Please try this PHP snippet. Please change 1,2,3
on the categories id that you want to remove from the selection and please change role name
on the role name which user has to not see some categories
add_filter(
'hivepress/v1/models/listing/fields',
function($fields){
if(!is_user_logged_in()){
return $fields;
}
// Get user.
$user = get_userdata(get_current_user_id());
if(in_array('role name', $user->roles)){
$disabled_categories_ids = [1,2,3];
if(isset($fields['categories']['options'])){
foreach($disabled_categories_ids as $category_id){
unset($fields['categories']['options'][$category_id]);
}
}
}
return $fields;
},
10000
);
bbb
February 23, 2023, 2:22pm
4
Worked perfectly! Thank you so much.
One more question, is it possible to remove the first selected null category which is “-” from the dropdown?
With best regards,
bb
yevhen
February 24, 2023, 4:46pm
6
Please try this PHP snippet.
add_filter(
'hivepress/v1/models/listing/fields',
function($fields){
if(isset($fields['categories'])){
$fields['categories']['placeholder'] = 'Custom text';
}
return $fields;
},
10000
);
bbb
February 24, 2023, 4:59pm
7
Hi again and thanks for your response!
I think you misunderstood me. I want to remove the “no category” selection which is represented by a “-“, not rename it to something else.
With best regards,
bb
ihor
February 25, 2023, 8:16pm
8
Unfortunately it’s not possible if the drop-down is optional, the placeholder is always there.
system
Closed
March 27, 2023, 8:16pm
9
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.