(function(){ const logPrefix = '[hide-products-if-subcats]'; const subSelectors = [ '.sub-cat-container', '.woocommerce-loop-category', 'li.product-category', '.product-category', '.wc-block-grid__product-category', '.woocommerce-category', '.woocommerce-ProductCategories', '.product-cats', '.term-list' ]; const prodSelectors = [ '.products', 'ul.products', '.wc-block-grid__products', '.woocommerce ul.products', '.elementor-widget-woocommerce-products', '.products-container', '.woocommerce-LoopProduct', '.products-grid' ]; function checkSubNode(node) { if(!node) return false; return node.querySelectorAll( 'li.product-category, .woocommerce-loop-category, .product-category, .wc-block-grid__product-category, a[href*="/product-category/"], a[href*="?product_cat="]' ).length > 0; } function findSub() { for (let sel of subSelectors) { try { const nodes = document.querySelectorAll(sel); if (nodes && nodes.length) { for (let n of nodes) if (checkSubNode(n)) return n; } } catch(e){} } // fallback: any link that looks like a category link const catLink = document.querySelector('a[href*="/product-category/"], a[href*="?product_cat="]'); return catLink ? (catLink.closest('ul,div,section') || catLink.parentElement) : null; } function findProductsContainer() { for (let sel of prodSelectors) { try { const el = document.querySelector(sel); if (el) return el; } catch(e){} } // fallback: locate an ancestor that holds many .product items const sample = document.querySelector('li.product, .product, .woocommerce-loop-product__title'); if (sample) { let anc = sample.parentElement; while (anc && anc !== document.body) { if (anc.querySelectorAll('li.product, .product').length > 0 && anc !== sample) return anc; anc = anc.parentElement; } } return null; } // add strong CSS rule const style = document.createElement('style'); style.textContent = '.hidden-by-subcats{display:none !important; visibility:hidden !important; height:0 !important; margin:0 !important; padding:0 !important;}'; document.head && document.head.appendChild(style); let done = false; const start = Date.now(); const interval = 500; const timeout = 60000; // 60s const timer = setInterval(()=>{ if (done) { clearInterval(timer); return; } try { const sub = findSub(); if (sub) { const prod = document.querySelector('.products-container') || findProductsContainer() || sub.nextElementSibling; if (prod) { prod.classList.add('hidden-by-subcats'); console.log(logPrefix, 'Hidden products container:', prod); done = true; clearInterval(timer); return; } else { console.log(logPrefix, 'Subcategories found but products container not detected yet.'); } } else { console.log(logPrefix, 'No subcategories detected yet.'); } } catch (err) { console.error(logPrefix, 'Error:', err); } if (Date.now() - start > timeout) { clearInterval(timer); console.log(logPrefix, 'Timeout reached; stopped checking.'); } }, interval); })();

Car Hauler Website

It seems we can’t find what you’re looking for. Perhaps searching can help.

Shopping Cart
Scroll to Top
Call Now Button