How to change a field label based on the category selected?

Thank you for waiting. Please try this PHP code snippet. Please change number 100 on the category ID where you want to change the Location field label

add_filter(
	'hivepress/v1/forms/listing_update',
	function($args, $form){
		
		// Get listing.
		$listing = $form->get_model();
		
		if(!$listing){
			return $args;
		}
		
		$category_ids = $listing->get_categories__id();
		
		if(!$category_ids){
			return $args;
		}
		
		if(in_array(100, $category_ids)){
			$args['fields']['location']['label'] = 'Custom location';
		}
		
		return $args;
	},
	1000,
	2
);
3 Likes