Hello,
I’m using HivePress with the Geolocation extension and I need help with making the Location field optional for specific listing categories.
My requirement: I have some listing categories where Location should be optional (not required), while for other categories it should remain required.
What I’ve tried: I attempted to use various HivePress filters in my child theme:
add_filter(‘hivepress/v1/forms/listing_submit’, ‘my_function’, 1000);
add_filter(‘hivepress/v1/forms/listing_update’, ‘my_function’, 1000);
add_filter(‘hivepress/v1/forms/listing_submit/errors’, ‘my_function’, 1000);
add_filter(‘hivepress/v1/models/listing/attributes’, ‘my_function’, 1000);
I was able to:
-
Hide the Location field using JavaScript for the specified categories
-
Add “(optional)” label to the field
-
Remove the
requiredattribute from the form field
The problem: Despite all these modifications, when submitting a listing without Location in these categories, I still get the validation error: “Location” field is required.
It seems the Geolocation extension has its own validation that runs regardless of the form field settings.
My questions:
-
Is there a proper hook or filter to make the Location field optional for specific categories?
-
Is there a way to disable the Geolocation extension’s validation for certain categories?
-
Can this be configured in the settings without custom code?
I would appreciate any guidance on the correct approach to implement this.
Thank you!