Removing items in /submit-listing/details/

Hi,
I already have my own custom fields prepared that I will be using in the form. I’d like to remove some of the default HivePress fields completely, so that they also won’t be required when submitting the form.

Does anyone know the best way to achieve this? Ideally, I’d like to do it with PHP code (e.g. via the Code Snippets plugin), so the changes are safe and permanent.

I’ve attached a print screen for reference.

Thanks in advance for any help!

Hi @Kamilos,

This is definitely possible, and, as you mentioned; using code snippets is the best way to achieve this.

If you could let us know which exact fields you’d like to remove, myself, or someone else in the community will be able to help.

Otherwise, if you search the forum for “remove xxxx” where xxxx is the field name, you’ll find existing examples for most fields.

I hope this helps!

Cheers,
Chris :victory_hand:

Yes, I saw it, so I wrote this code:

// 1) BACKEND: set requirement = false (especially for price)

add_filter('hivepress/v1/models/listing', function($model){
foreach (['title','price','location','images','tags','description'] as $key) {
if (!empty($model['fields'][$key])) {
$model['fields'][$key]['required'] = false;

// For price, remove hard validation rules (required|min:0)

if ($key === 'price' && !empty($model['fields']['price']['validation']) && is_string($model['fields']['price']['validation'])) { 
$rules = $model['fields']['price']['validation']; 
$rules = preg_replace('/(^|\|)required(\||$)/', '$1', $rules); 
$rules = preg_replace('/(^|\|)min:0(?:\.0+)?(\||$)/', '$1', $rules); 
$rules = trim(preg_replace('/\|{2,}/','|',$rules), '|'); 
$model['fields']['price']['validation'] = $rules; 
$model['fields']['price']['default'] = $model['fields']['price']['default'] ?? ''; 
} 
} 
} 
return $model;
}, 9999);

// (optional) loosen REST – when the form goes through endpoints

add_filter('hivepress/v1/rest/listings/args', function($args){ 
foreach (['title','price','location','images','tags','description'] as $key) { 
if (isset($args[$key])) { 
$args[$key]['required'] = false; 
$args[$key]['validate_callback'] = '__return_true'; 
} 
} 
return $args;
}, 9999);

// 2) FRONTEND: remove fields from STEP “details” (this is /submit-listing/details/)

$strip_details = function(array $form){
if (empty($form['fields']) || !is_array($form['fields'])) return $form;
foreach ($form['fields'] as $k => $def) {
$name = $def['name'] ?? $k; // some add-ons use their own keys, but set 'name'
if (in_array($name, ['title','price','location','images','tags','description'], true)) {
unset($form['fields'][$k]);
}
}
return $form;
};

// Adding and editing – specifically the “details” step
add_filter('hivepress/v1/forms/listing_submit_details', $strip_details, PHP_INT_MAX);

add_filter('hivepress/v1/forms/listing_update_details', $strip_details, PHP_INT_MAX);

although it doesn’t work

Hi @Kamilos,

Please see working examples in these topics:

I hope this helps!

Cheers,
Chris :victory_hand:

1 Like