Filter the enabled setting for listing inquiries.
Parameters
$allow
$params
(array) associative array with contextual data
You need to have a working knowledge of Hooks before you get started.
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
// For JReviews 3.x and earlier use dd instead of fwd_dd
// fwd_dd($allow, $params);
return $allow;
});
Development & Support
Customizations are not included with support. We provide this information to make it easier for developers to extend the functionality. From time to time we may have some availability for custom work. Get in touch to see if there's an opportunity to work together.
Examples
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
-
/services/authorization/listing_permissions.php