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
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.
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).
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.