Hide send message buttons if no listings

Hello! Is there a way to hide the send message buttons if a vendor does not have any listings?

Thanks

Hi,

Unfortunately, there’s no such feature; it would require a custom implementation.

Can I make it so if a vendor does not have listings, the user receives an error and cannot send messages? Something like this? I cannot get this to work btw.

add_filter(
    'hivepress/v1/models/message_send',
    function( $props ) {
        $listing_count = \HivePress\Models\Listing::query()->filter(
            [
                'status' => 'publish',
                'user'   => get_current_user_id(),
            ]
        )->count();

        if ($listing_count === 0) {
            $props['can_send'] = false; // Set to false to prevent sending the message
            $props['errors'][] = 'Unable to send message to vendor with no listings.';
        }

        return $props;
    }
);

Please try this PHP code snippet

add_filter(
	'hivepress/v1/forms/message_send/errors',
	function($errors, $form){
		$values = $form->get_values();
		
		if(!$values){
			return $errors;
		}
		
		$user_id = hivepress()->helper->get_array_value($values, 'recipient');
		
		if(!$user_id){
			return $errors;
		}
		
		$vendor_id = \HivePress\Models\Vendor::query()->filter(['user' => $user_id])->get_first_id();
		
		if(!$vendor_id){
			return $errors;
		}
		
		$listing_count = \HivePress\Models\Listing::query()->filter(['vendor' => $vendor_id])->get_count();
		
		if($listing_count > 0){
			return $errors;
		}
		
		$errors[] = 'Unable to send message to vendor with no listings.';
		return $errors;
	},
	1000,
	2
);
1 Like

This is gold! Thank you!

Do you happen to have a snippet to turn the “Request to Book” button the secondary color instead of the primary color? Thanks

Hi,

Please use this CSS snippet (How to add custom code snippets - HivePress Help Center):

.hp-form--booking-make .hp-field--submit {
	background-color: purple;
}

​I hope this is helpful to you.

Thanks for the reply! This works thanks!

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