Hide categories only for a specific plan

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 your_membership_plan_id on the membership plan id which hides these categories. Also please note that it can require further customization. If you are not familiar with code customization then please consider hiring someone for custom work https://fvrr.co/32e7LvY


add_filter(
	'hivepress/v1/models/listing/fields',
	function($fields){
		if(!is_user_logged_in() || !hivepress()->get_version('memberships')){
			return $fields;
		}
		
		$membership = \HivePress\Models\Membership::query()->filter(['user' => get_current_user_id()])->get_first();

        if(!$membership || your_membership_plan_id === $membership->get_plan__id()){
            $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
);
1 Like