Hide item fields in listing form when booking extension is activated

I am using both the marketplace extension and booking extension on the experthive theme, and there seems to be conflict between the two in the listing form.

When the booking extension is activated, the purchase note item field for the categories selected for selling is not displayed, instead, the security deposit field is displayed.

Also, the discount, extras, and security deposit item fields are displayed for ordinary listing categories that have not been selected for booking or selling.

I would like that this be corrected, and let the booking item field be only displayed for categories selected for booking without interfering with the functions of the marketplace extension.

Meanwhile, kindly provide a code snippet that I can use to hide the security deposit, extras, and discount item fields in the listing form for selected categories (categories not selected for selling or booking). And also a code snippet that I can use to display the purchase note item field in the listing form for categories selected for selling. Please note, the purchase note item field is always displayed when the booking extension is deactivated, it only disappears when the booking extension is activated.

Thank you.

Hi,

Please note that the feature of restricting selling categories works only for Marketplace, it will not work for Bookings. For Bookings, you can only use this feature: How to restrict booking to specific listing categories - HivePress Help Center. However, as a workaround, we can provide a temporary fix to hide the price field for listings of a specific category in the add listing form. Let me know if this works for you.

I have done as directed in the help post you referenced in the link, it restrict some specific booking item fields to the selected category except security deposit, extras, and discounts. It also removes purchase note item field in the listing form for categories selected for selling.

Please I would really appreciate a temporary fix while you work to fix the issue.

Thank you.

Sorry for the delay. Please try this code snippet:

add_filter(
	'hivepress/v1/models/listing/fields',
	function ( $fields, $model ) {
		$category_ids = wp_get_post_terms( $model->get_id(), 'hp_listing_category', [ 'fields' => 'ids' ] );

		if ( array_intersect( [ 1,2,3 ], $category_ids ) ) {
			unset( $fields['price_extras'], $fields['discounts'], $fields['booking_deposit'] );
		} else {
			unset( $fields['purchase_note'] );
		}

		return $fields;
	},
	1000,
	2
);

Replace 1,2,3 with category ID where you want to hide the security deposit, price extras and discounts, for other categories the purchase note will be hidden.

Please note that further customizations may be required, as some features may rely on the removed fields.

Hope this helps

I’ve done this, and the code doesn’t work. I replaced the “1,2,3” with the category IDs for the main category and even to the last subcategories, it doesn’t still work, the ‘security deposit’, ‘discount’, and ‘extras’ fields are still displayed in the listing form for the categories.

By the way, I wasn’t looking to hide the purchase note field. I wanted it the purchase not field to be displayed for categories that have been selected for selling, even when the booking extension is activated.

In general, I hope you’ve taken into consideration that these issues occur only when the booking extension is activated.

Please try this code snippet instead:

add_filter(
	'hivepress/v1/forms/listing_update',
	function ( $form_args, $form ) {
		$listing = $form->get_model();

		if ( ! $listing ) {
			return $form_args;
		}

		if ( array_intersect( [ 1,2,3 ], (array) $listing->get_categories__id() ) ) {
			unset( $form_args['fields']['price_extras'], $form_args['fields']['discounts'], $form_args['fields']['booking_deposit'] );
		}

		if ( array_intersect( [ 4,5,6 ], (array) $listing->get_categories__id() ) ) {
			unset( $form_args['fields']['purchase_note'] );
		}

		return $form_args;
	},
	1000,
	2
);

It will hide the price extras, discounts, and security deposit fields for categories 1,2,3, and hide the purchase note field for categories with 4,5,6 IDs. Please adjust these IDs to match the existing settings.

Thank you very much. The first part of the code works perfectly well to hide the ‘Price Extras’, ‘Discounts’, and ‘Security Deposit’ fields in the listing form for selected categories.

However, concerning the second part of the code as copied thus:
if ( array_intersect( [ 4,5,6 ], (array) $listing->get_categories__id() ) ) {
unset( $form_args[‘fields’][‘purchase_note’] );
it seems you didn’t understand the issue.

As you have stated, this part of the code hides the ‘purchase note’ field from the listing form for selected categories. However, this is the opposite of what I needed. Currently, with the activation of the booking extension, the purchase note field is not displayed for the categories selected for selling in the Hivepress Listing settings. I wanted a code snippet that would allow or set the ‘purchase not’ field to be displayed for the selected categories, not the one that will hide or unset the ‘purchase note’ field.

Thank you.

Thanks for your patience.

You can try this code snippet (please replace 1,2,3 with category IDs where you want to show the Purchase note):

add_filter(
	'hivepress/v1/models/listing/attributes',
	function ( $attributes ) {
		if ( isset( $attributes['purchase_note'] ) ) {
			$attributes['purchase_note']['categories'] = [ 1,2,3 ];
		}

		return $attributes;
	},
	1000
);

This works well.

The only issue was that it is displayed as ‘Booking Note’, but I have used the Loco translate plugin to change the label to ‘Order Note’, and description to something about order instead of just booking.

Thank you.

1 Like