Home Support Extensions Claim Listings Limiting claim listing to one per account

Limiting claim listing to one per account

  • Author
    Posts
  • Jj72ny

    Is there a way to limit an account to only claiming one listing per account

    ihor developer

    Sure, but with a code snippet, please try adding this code at the end of the child theme functions.php file (so updates will not erase it):

    add_filter(
    	'hivepress/v1/models/listing_claim/errors',
    	function( $errors, $claim ) {
    		if ( ! $claim->get_id() && empty( $errors ) && HivePress\Models\Listing_Claim::query()->filter(
    			[
    				'user' => $claim->get_user__id(),
    			]
    		)->get_first_id() ) {
    			$errors[] = 'Add error message here.';
    		}
    
    		return $errors;
    	},
    	10,
    	2
    );

    It will allow only one listing claim per account.

    Jj72ny

    works great i was hoping it would force the “claim listing” button to disappear. but this will work also is it possible to make”claim listing” the roll specific

    ihor developer

    Hiding it would require more customizations (checking if claim is submitted inside the template). Please let me know what you mean about the roll specific.

    Jj72ny

    Sorry I miss spelled role
    I have three roles on my page admin contractor and subscriber all can add listings but only contractors need claim a listing and only can claim one ( if it’s their business) basically a subscriber can add a contractor that they know or have used if the contractor isn’t listed yet and that contractor can claim that listing as their own and build on it as they choose it sounds like it may take more than just a small change so I can deal with what I have if it is

    ihor developer

    Seems like limiting claims to 1 per account may work, or there’re other requirements? “Claim listing” link will be hidden anyway if listing is claimed, there will be a “verified” badge instead.

    Jj72ny

    yes i think this will work i kinda only wanted the contractor role to be able to see the unclaimed “claim listing” but this will do just fine as is

Viewing 7 posts - 1 through 7 (of 7 total)

The topic ‘Limiting claim listing to one per account’ is closed to new replies.