Hide categories only for a specific plan

Guys, I saw the following forum post and it met my project needs: Hide "Add a listing" Button only to specific Plan

Now I would like to hide the categories according to the plan chosen in the Membership extension. I am referring to the categories on the page /submit-listing/details/

Similar to what is done using the following PHP snippet

But according to the user’s active plan.

Hi,
If you mean preventing adding listings to specific categories with Memebrships, untofunately there’s no such feature because Memberships don’t restrict the listing submission, it restricts viewing listings, vendors or specific details. We plan to create a single monetization extension that will include features of both Paid Listings and Memberships, it’ll probably be released as a Memberships update.

ihor i believe it is possible from a code similar to what yevhen solved in the topics above. If it is possible to hide the ad button according to the plan, and it is also possible to hide categories at the time of making the ad it is possible to do it by the user’s plan.

Yevhen see if it’s possible, I believe it’s just a mix of the two codes from the topics above.

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

yevhen I’m your fan man! It worked perfectly, I was looking forward to this solution :pray:

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.