Individual users should bypass membership requirement - need code snippet

Hello,

I have a marketplace site built with HivePress + Memberships plugin.

My setup:

  • I created a user attribute called “Account Type” (field name: hesap_turu) with two options: bireysel (individual) and kurumsal (business)

  • I have 3 membership plans: START, BUSINESS, PRO — these are for business users only

What I need:

  • Individual users (bireysel) = can submit listings for FREE without any membership

  • Business users (kurumsal) = must select a membership plan before submitting listings

The attribute is saved in user meta as hp_hesap_turu with values bireysel or kurumsal.

I tried this code snippet but it doesn’t work:

php

add_filter('hivepress/v1/models/listing/submit', function($allowed, $listing) {
    $user_id = get_current_user_id();
    $hesap_turu = get_user_meta($user_id, 'hp_hesap_turu', true);
    if ($hesap_turu === 'bireysel') {
        return true;
    }
    return $allowed;
}, 10, 2);

Could you please provide the correct code snippet?

Thank you!

Hey @alevtina,

I haven’t tested this, but here’s HivePress’s AI response:


Hello!

Thank you for reaching out. I understand you want to allow individual users (bireysel) to submit listings for free, while business users (kurumsal) must have an active membership plan.

The issue with your code snippet is that you’re using the wrong hook. The hivepress/v1/models/listing/submit hook doesn’t work that way for this use case. Instead, you should use the hivepress/v1/forms/listing_submit filter to conditionally modify the form based on the user’s account type.

Here’s the corrected approach:

add_filter(
    'hivepress/v1/forms/listing_submit',
    function( $form ) {
        $user_id = get_current_user_id();
        
        if ( ! $user_id ) {
            return $form;
        }
        
        $hesap_turu = get_user_meta( $user_id, 'hp_hesap_turu', true );
        
        // If user is "bireysel" (individual), allow free submission
        if ( $hesap_turu === 'bireysel' ) {
            return $form;
        }
        
        // If user is "kurumsal" (business), check for active membership
        $membership = \HivePress\Models\Membership::query()
            ->filter( [ 'user' => $user_id ] )
            ->get_first();
        
        // If no membership, the form will be blocked by Memberships settings
        // Make sure your membership plans have "Submission Limit" set in the Listings section
        
        return $form;
    },
    1000
);

However, the most important part is your Memberships configuration:

  • Go to HivePress > Settings > Memberships
  • In the Listings dropdown, select All Pages (this enables listing restrictions)
  • Go to Memberships > Plans and edit each of your business plans (START, BUSINESS, PRO)
  • In the Listings section, set a Submission Limit (e.g., 5, 10, 20 listings depending on the plan)
  • Make sure you don’t set a submission limit for any free plan that individual users might have

This way:

  • Bireysel users without a membership can submit listings freely
  • Kurumsal users will be redirected to select a plan when they try to add a listing

I hope this helps!

Cheers,
Chris :victory_hand:

1 Like

I tested the previous snippet and it does not solve the issue.

Current behavior:

  • When a user clicks “Add Listing”, both Bireysel and Kurumsal users are redirected to the membership plans page.
  • Both user types see all 4 plans:
    BIREYSEL, START, BUSINESS, PRO.

Expected behavior:

  1. If user meta hp_hesap_turu = bireysel:
  • user should be able to submit listings without being redirected to the membership plans page;
  • user should not need to select any membership plan;
  • if the plans page is opened manually, only the BIREYSEL plan should be visible, or ideally no plans should be shown.
  1. If user meta hp_hesap_turu = kurumsal:
  • user must select START, BUSINESS, or PRO before submitting listings;
  • BIREYSEL plan must be hidden from Kurumsal users;
  • if no active membership exists, redirect to the membership plans page.

Questions:

  1. What is the correct HivePress hook/filter to bypass Memberships listing submission restrictions only for Bireysel users?

  2. What is the correct HivePress hook/filter to filter membership plans shown on the plans page depending on the user type?

  3. Please confirm the correct meta key for a HivePress user attribute with slug hesap_turu. Is it hp_hesap_turu?

  4. Should this logic be implemented via user attributes, vendor attributes, or WordPress roles?

One more clarification about the architecture.

Maybe I’m thinking about this incorrectly.

For BitkiMO, I need two account types:

  1. Bireysel:
  • private user
  • can submit listings for free
  • no membership required
  • no business/vendor profile
  1. Kurumsal:
  • business/vendor account
  • must select START/BUSINESS/PRO membership before submitting listings
  • has business/vendor profile

What is the correct HivePress architecture for this?

Should Bireysel be a regular User and Kurumsal be a Vendor?

Can Memberships restrictions be applied only to Vendors, while regular Users can submit listings freely?

Or does this require custom code?

Also, should the account type be implemented as a User Attribute, Vendor Attribute, or WordPress role?

Hi,

We’d like to suggest a slightly different approach that could simplify things considerably. Instead of using a custom user attribute to handle account type selection in the registration form, you may want to consider using Vendor Categories, for example, creating two categories such as Individual and Business. This would essentially serve as the account type selector, and as an added benefit, it would also allow you to add category-specific attributes to vendor profiles down the line.

One thing worth noting is that the registration form is currently shared with regular users who don’t need to add listings or see memberships, etc. Using Vendor Categories would help streamline this, as users who attempt to add a listing would naturally be prompted to select their vendor category, effectively choosing their account type.

The remaining step would be to add a way to skip the Select Plan page depending on the selected category, and we can provide guidance on that once the first part is in place.

Hi,

Thank you. This is actually how my site is currently set up.

I already use Vendor Categories as the account type selector:

  • Bireysel / Individual
  • Kurumsal / Business

The user selects the vendor category during the Complete Profile step.

The issue is the remaining step: when a vendor selects Bireysel / Individual, the Select Plan page is still shown by the Memberships extension.

What I need now is specifically a snippet for this part:

If vendor category = Individual:

  • Skip the Select Plan page
  • Allow the user to continue directly to listing submission
  • Ideally auto-assign the free Individual membership plan, so Memberships still works normally

If vendor category = Business:

  • Keep the Select Plan page
  • Show only START / BUSINESS / PRO plans
  • Hide the free Individual plan

Could you provide the recommended hooks/snippet for skipping or auto-assigning the free plan based on the selected Vendor Category?

Thank you.

Hi,

Please try using the code snippets below:

add_action(
	'hivepress/v1/models/vendor/update_categories',
	function( $vendor_id, $category_ids ) {
		$category_id = 123;
		$plan_id     = 123;

		if ( ! in_array( $category_id, (array) $category_ids ) ) {
			return;
		}

		$vendor = hivepress()->model->get_model_object( 'vendor', $vendor_id );
		$plan   = hivepress()->model->get_model_object( 'membership_plan', $plan_id );

		if ( ! $vendor || ! $plan ) {
			return;
		}

		hivepress()->membership->add_membership( $vendor->get_user__id(), $plan );
	},
	10,
	2
);

add_action(
	'pre_get_posts',
	function( $query ) {
		$plan_id = 123;

		if ( is_admin() || hivepress()->helper->is_rest() ) {
			return;
		}

		if ( $query->get( 'post_type' ) !== 'hp_membership_plan' || hivepress()->router->get_current_route_name() !== 'membership_plans_view_page' ) {
			return;
		}

		$query->set( 'post__not_in', [ $plan_id ] );
	}
);

Replace 123 with the corresponding plan (the unlimited one that should be assigned on registration, and hidden on the Select Plan page) and category IDs (category of vendors that should get this plan on registration). You can check plan and category IDs when editing a plan (something like “…post=123…” in the browser address bar) or category (“…tag=123…” in the address bar when editing).

Hope this helps

Hi Ihor,

Thank you! I’ll try your code snippet.

I also came up with my own approach, and so far it seems to work without modifying HivePress core or affecting future updates. I’m going to test it thoroughly, and if everything works correctly, I’ll share it here as well. It might be useful for others who need the same functionality.

Thank you again for your help!

1 Like

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