Hello,
Is there a way of hiding or making it an option to have location for listings. Some of my listings are online classes etc.
Many thanks
Linsey
Hello,
Is there a way of hiding or making it an option to have location for listings. Some of my listings are online classes etc.
Many thanks
Linsey
Hi,
Unfortunately, there’s no such feature, it would require a custom implementation. If customizations are required for your site, please try customizing it using the collection of code snippets Search · user:hivepress · GitHub and other developer resources, or consider hiring someone for custom work https://fvrr.co/32e7LvY
Thank you. Managed to create a snippet that worked
@LinseyR Please do share your snippet. thanks
// Make the location field optional for listings in HivePress
add_filter( 'hivepress/v1/models/listing/fields', function ( $fields ) {
if ( isset( $fields['location'] ) ) {
$fields['location']['required'] = false;
}
return $fields;
}, 100 );
// Hide the location block on the single listing page if not set
add_filter( 'hivepress/v1/templates/listing_view_page/blocks', function ( $blocks ) {
$listing = hivepress()->request->get_context( 'listing' );
if ( $listing && ! $listing->get_location() ) {
foreach ( $blocks as $key => $block ) {
if ( isset( $block['type'] ) && $block['type'] === 'location' ) {
unset( $blocks[ $key ] );
}
}
}
return $blocks;
}, 100 );
// Hide the location in listing cards (grid/list views) if not set
add_filter( 'hivepress/v1/templates/listing_view_block/blocks', function ( $blocks, $template ) {
$listing = $template->get_context( 'listing' );
if ( $listing && ! $listing->get_location() ) {
foreach ( $blocks as $key => $block ) {
if ( isset( $block['type'] ) && $block['type'] === 'location' ) {
unset( $blocks[ $key ] );
}
}
}
return $blocks;
}, 100, 2 );
// Force Location to be optional at form validation level
add_filter( 'hivepress/v1/forms/listing_submit', function( $form ) {
if ( isset( $form['fields']['location'] ) ) {
$form['fields']['location']['required'] = false;
}
return $form;
}, 100 );
// Make the location field optional on the edit listing form too
add_filter( 'hivepress/v1/forms/listing_update', function( $form ) {
if ( isset( $form['fields']['location'] ) ) {
$form['fields']['location']['required'] = false;
}
return $form;
}, 100 );
thanks @LinseyR but it says failed to create snippet with status code 500
solved it… thanks… issue with single quote