Join our new community forum for support & discussion
Join NowHome › Support › Extensions › Bookings › Hide bookings extension/price attribute for certain categories/sub-categories
Hide bookings extension/price attribute for certain categories/sub-categories
-
AuthorPosts
-
artshareco 1 year, 5 months ago
Hi Ihor,
Could you please provide a snippet to hide the bookings extension in certain categories/sub-categories? I just need to use it for one sub-category. I would also like to hide the price attribute in those same categories/sub-categories where the bookings and marketplace extensions aren’t needed. Thanks!
Please try this one:
add_filter( 'hivepress/v1/models/listing/attributes', function( $attributes ) { $category_ids = [ 1, 2, 3 ]; if ( isset( $attributes['price'] ) ) { $attributes['price']['categories'] = $category_ids; } if ( isset( $attributes['booking_offset'] ) ) { foreach ( $attributes as $name => $args ) { if ( strpos( $name, 'booking' ) === 0 ) { $attributes[ $name ]['categories'] = $category_ids; } } } return $attributes; }, 1000 );
If you replace 1,2,3 with category IDs then the price field and booking-specific settings will appear for listings assigned to these categories only.
artshareco 1 year, 5 months agoThanks for your reply Ihor,
What do you mean by category ID? Is it the name of the category?
artshareco 1 year, 5 months agoOk I’ve found the category_id of the category I want to use the bookings extension with and replaced 1,2,3 for it but the snippet doesn’t work. The bookings extension is still visible in every category. What could be the issue?
artshareco 1 year, 5 months agoOk, sorry Ihor. It does work! I just thought that the snippet would hide the bookings extension from the listing ‘front-end’. Anyway, it’s great to hide those fields from the edit-listing section as it’s something I was going to ask you anyway.
Is it possible to hide the bookings ‘frame’ from the ‘front-end’ (listing display) using a CSS snippet? I only use one sub-category for bookings while the other categories are used for other listing types.
Many thanks!
You can try this one to hide the front-end form:
add_filter( 'hivepress/v1/templates/listing_view_page/blocks', function( $blocks, $template ) { $listing = $template->get_context( 'listing' ); if ( $listing && ! array_intersect( [ 1, 2, 3 ], (array) $listing->get_categories__id() ) ) { $blocks = hivepress()->helper->merge_trees( [ 'blocks' => $blocks ], [ 'blocks' => [ 'booking_make_form' => [ 'type' => 'content', ], ], ] )['blocks']; } return $blocks; }, 1000, 2 );
Please replace 1,2,3 with ID(s) of the listing categories.
artshareco 1 year, 5 months agoFantastic! It works like a charm Ihor. I’m now able to use both Bookings/Marketplace extension in only one sub-category. Thanks so much for your help.
Jave 1 year, 5 months agoHey Ihor,
i got a question regarding this code too. Using it to hide reviews for specific categories and it works just fine. but how can i hide the “add to favourites” link on the listing page for specific categories? Using ‘listing_favorite_toggle’ does not seem to work with this snippet
artshareco 1 year, 5 months agoHi Ihor,
I’ve just noticed that the ‘calendar’ tab next to details, edit etc. is still visible in the categories/sub-categories where the bookings extension is disabled. Is it possible to hide this as well?
@Jave Please try using the same snippet, but for the “listing_favorite_link” block, if you set its type to “content” the link should disappear.
@artshareco You can try this snippet, but please note that there may be other places where booking options are still visible, this may require further customization:add_filter( 'hivepress/v1/menus/listing_manage/items', function( $items, $menu ) { $listing = $menu->get_context( 'listing' ); if ( $listing && ! array_intersect( [ 1, 2, 3 ], (array) $listing->get_categories__id() ) ) { unset( $items['listing_calendar'] ); unset( $items['listing_bookings'] ); } return $items; }, 1000, 2 );
artshareco 1 year, 5 months agoIt works, thanks!. So far so good but I’ll let you know if I need further customisations.
-
AuthorPosts
New Reply
This forum has been archived and is no longer accepting new posts or replies. Please join our new community forum for support & discussion.