Restrict Opening Hours to certain categories and hide Open 24/7 where applicable

Hey,

I’m currently designing another site that has a more complex attribute/category selection process. I found the following snippet to only display the ‘Opening Hours’ field on certain categories:

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		$category_ids = [ 61, 50, 57, 60, 54, 56, 52, 58, 55, 59 ];

		if ( isset( $attributes['opening_hours'] ) ) {
			$attributes['opening_hours']['categories'] = $category_ids;
		}

		return $attributes;
	},
	1000
);

This works perfectly to restrict which categories of which the ‘Opening Hours’ field displays on. However, the “Open 24/7” checkbox remains on all categories.

I also found this CSS snippet:

.hp-template--listing-submit-details-page .hp-field--opening-hours .hp-field--checkbox{
	display:none !important;
}

Which hides the checkbox completely, but this isn’t what I need.

Instead, I’d like to restrict the ‘Opening Hours’ field and the ‘Open 24/7’ checkbox to only show certain on certain categories.

If @andrii or @ihor could kindly provide a snippet to help achieve this, that would be amazing!

Many thanks in advance
~ Chris :victory_hand:

Hi,

Please try extending the code snippet this way:

add_filter(
	'hivepress/v1/models/listing/attributes',
	function( $attributes ) {
		$category_ids = [ 61, 50, 57, 60, 54, 56, 52, 58, 55, 59 ];

		if ( isset( $attributes['opening_hours'] ) ) {
			$attributes['opening_hours']['categories'] = $category_ids;
			$attributes['always_open']['categories'] = $category_ids;
		}

		return $attributes;
	},
	1000
);
1 Like

Thank you very much, @ihor - that’s working perfectly! :folded_hands:

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