listing_allows_inquiries
Filter the enabled setting for listing inquiries.
You need to have a working knowledge of Hooks before you get started.
Parameters
Name | Type | Description |
---|---|---|
$allow |
parameter |
(boolean) |
$params |
parameter |
(array) associative array with contextual data |
Boilerplate Code
Use the boilerplate code to start using the filter, and add your own logic to modify the first argument and return it.
Clickfwd\Hook\Filter::add('listing_allows_inquiries', function($allow, $params)
{
// Uncomment line below to view available data passed into hook
// fwd_dd($allow, $params);
return $allow;
});
Examples
- Enable Inquiries Only for Logged in Users
- Enable Inquiries Only for Claimed Listings
- Disable inquiries when email custom field is empty
- Enable Inquiries for Paid Listings
Enable Inquiries Only for Logged in Users
Clickfwd\Hook\Filter::add('listing_allows_inquiries', function($allow, $params)
{
$auth = S2Object::make('auth');
return $auth->connected;
}, 10);
Enable Inquiries Only for Claimed Listings
Clickfwd\Hook\Filter::add('listing_allows_inquiries', function($allow, $params)
{
$listing = $params['listing'];
$allow = $listing['Claim']['approved'] ?? false;
return $allow;
}, 10);
Disable inquiries when email custom field is empty
The default functionality when using an email custom field to set the recipient of inquiries is to fallback to the listing owner when the field is empty. This filter allows changing the behavior so the functionality is disabled when the field is empty.
Clickfwd\Hook\Filter::add('listing_allows_inquiries', function($permission, $params)
{
$listing = $params['listing'];
$config = S2App::make('config');
$config->withType($listing['ListingType']['listing_type_id']);
// Abort when not using custom field
if ($config->inquiry_recipient !== 'field') {
return $permission;
}
// Disable inquiries when email field is empty
if (empty($listing['Field']['pairs'][$config->inquiry_field])) {
return false;
}
return $permission;
}, 10);
Enable Inquiries for Paid Listings
Clickfwd\Hook\Filter::add('listing_allows_inquiries', function($allow, $params)
{
$listing = $params['listing'];
$premiumPlanIds = [1,2,3];
$allow = isset($listing['Paid']) && array_intersect($premiumPlanIds, $listing['Paid']['plan_ids']);
return $allow;
}, 10);
Source Files
/services/authorization/listing_permissions.php