Snippets Collections
 https://gist.github.com/aalexandr21/23794f7473a46de2e024a2542afb3155

I added it here https://prnt.sc/5Oc1TgkXsaGc
And to listings that you need to hide, I added the CSS class hide_when_use_filter https://prnt.sc/XaE35kAG5Ddp

/**Snippet**/


jQuery(document).ready(function ($) {
    document.addEventListener('jet-smart-filters/inited', function (initEvent) {
        JetSmartFilters.events.subscribe('activeItems/change', function (activeItems) {
            if (activeItems && activeItems.length >= 1) {
                $(".hide_when_use_filter").slideUp();
            }
            else {
                $(".hide_when_use_filter").slideDown();
            };
        });
    })
});
<style>

    body:not(.elementor-editor-active) .hide-listing {
        display: none;
        height: 0;
    }
    
</style>

<script>

	document.addEventListener( 'jet-smart-filters/inited', function( initEvent ) {
		
		function hideProvider( $provider, parentSelector ) {
			$provider.closest( parentSelector ).addClass( 'hide-listing' );
		}
		
		function showProvider( $provider, parentSelector ) {
			$provider.closest( parentSelector ).removeClass( 'hide-listing' );
		}
		
		jQuery( function( $ ) {
			
			for ( const groupName in window.JetSmartFilters.filterGroups ) {
				
				const filterGroup = window.JetSmartFilters.filterGroups[ groupName ],
				      $provider   = filterGroup?.$provider,
				      query       = filterGroup?.currentQuery || {};
					
				if ( ! $provider.closest('.hide-before-filter')?.length ) {
					return;
				}
				
				if ( ! Object.keys( query ).length ) {
					hideProvider( $provider, '.hide-before-filter' );
				} else {
					showProvider( $provider, '.hide-before-filter' );
				}
				
			}
			
			window.JetSmartFilters.events.subscribe( 'ajaxFilters/updated', function( provider, queryId ) {
				
				const filterGroup = window.JetSmartFilters.filterGroups[ provider + '/' + queryId ],
				      $provider   = filterGroup.$provider,
				      query       = filterGroup.currentQuery || {};
				
				if ( ! Object.keys( query ).length ) {
					hideProvider( $provider, '.hide-before-filter.hide-on-reset' );
				} else {
					showProvider( $provider, '.hide-before-filter' );
				}
				
			} );
		
		} );
	
	} );
	
</script>
star

Fri Apr 19 2024 20:03:25 GMT+0000 (Coordinated Universal Time)

#filter #jetsmartfilters
star

Mon Apr 15 2024 19:02:38 GMT+0000 (Coordinated Universal Time)

#jetsmartfilters #filter

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension