Remove field from update form but not submit form

Hi,

I want to hide a field on the listing update form so I used this snippet to unset the attribute:

add_filter(
   'hivepress/v1/forms/listing_update',
   function( $form ) {
       unset($form['fields']['my_attribute']); 

       return $form;
   },
   1000
);

But since listing_submit inherits from listing_update it is also hidden on the submit page which is an unwanted result. I can not figure out what snippet to use to add it back via hivepress/v1/forms/listing_submit.

Maybe I should add a condition to check the page or form? If yes, how should I do that best?

Any help to disable the field in the proper way is welcome :slight_smile:

Thank you!

Sorry for the delay. This hook allows passing a second argument, the form object which allows you to check the form name:

$form::get_meta('name')

Thanks ihor.

I used it in this code and it is working! Thanks a lot!

add_filter(
	'hivepress/v1/forms/listing_update',
	function($args, $form) {
		$form_name = $form::get_meta('name');
		
		if('listing_update' === $form_name) {
			unset( $args['fields']['my_attribute'] );
		}
		
		return $args;
	},
	1000,
	2
);
2 Likes

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