Restrict making offers to users with listings only

Hello. Is it possible that only people with an active listings can reply to request?

Hi,
Yes, it works this way by default (vendor profiles are registered only if at least one listing is added), and only vendors can make offers for requests.

Yes, I know, but if the ad expires, they can still make offers. My point is that this option is only available to those who have active(published) ads. Not as draft or pending

Hi,
Yes, the user remains a vendor even if the listing has expired. This status and profile are assigned if at least one listing is left and is not automatically removed.

That’s why I’m asking if anyone has a code that checks it and blocks the possibility of offering in the event of an inactive ad.

Unfortunately there’s no simple code snippet for this, in the current version the vendor status is not revoked from user if the last listing they have is expired because they can still renew it. Vendor profile can be only removed manually.

I wrote a custom filter myself. Maybe someone will like it someday.

add_filter(
	'hivepress/v1/forms/offer_make/errors',
	function( $errors, $form ) {
			$listing_count = \HivePress\Models\Listing::query()->filter(
				[
					'status__in' => 'publish',
					'user'       => get_current_user_id(),
				]
			)->get_count();

			if ( $listing_count == 0 ) {
				$errors[] = 'Error text';
			}
		return $errors;
	},
	1000,
	2
);
1 Like

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