How to make Location field optional for specific listing categories?

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 required attribute 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:

  1. Is there a proper hook or filter to make the Location field optional for specific categories?

  2. Is there a way to disable the Geolocation extension’s validation for certain categories?

  3. Can this be configured in the settings without custom code?

I would appreciate any guidance on the correct approach to implement this.

Thank you!

Hi @Mart,

This snippet will make the location field optional for listings. It may suit your needs, as is, or you can try restricting it to only certain categories by extending the code.

I hope this helps!

Cheers,
Chris :victory_hand:

1 Like

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