how to hide products on collection page in frontend?

how to hide products on collection page in frontend?

naeh-paradies
Shopify Partner
3 0 0

In our store, we have a lot of products with variant. to comply with shopify restrictions, i unfortunately had to split the variants into products. depending on metafields, the products are shown as a product with variants in frontend. no probs here. to avoid the dieferent products to be displayed on the collection page, i only render the product with lowest price. so far so good.
now the problem:
collection.products_count is not affected by the number of products i render.
therefor a wrong number of products are shown in the header of the product page render.
a wrong number of products are shown in the available products count in filters and the "load more" button at the bottom of the page.

does anyone have an idea how work around it and solve the problem?

Reply 1 (1)

mageplaza-cs
Shopify Partner
494 42 82

Hi @naeh-paradies 

I am from Mageplaza - Shopify solution expert.

 

In case you have successfully displayed the product list as desired, but collection.products_count is not showing correctly, I will guide you on how to fix this issue in the best way:

collection.products_count is generated server-side and cannot be changed in Liquid. Therefore, you need to add a JavaScript snippet to handle the display on the client side:

Step 1: Open the file that contains the code for displaying your product list. It usually uses ul and li tags. For example, the file: main-collection-product-grid.liquid.

Step 2: Add the following JavaScript code inside the ul tags, as shown in the example below.

<script>
  document.addEventListener('DOMContentLoaded',
    function() {
      let countProductRender    = document.querySelectorAll('ul#product-grid li').length,
          productCountDesktopEL = document.querySelector('#ProductCountDesktop'),
          productCountMobileEl    = document.querySelector('#ProductCount');
      productCountDesktopEL.innerText = `${countProductRender} products`;
      productCountMobileEl.innerText    = `${countProductRender} products`;
    }
  );
</script>

2025-04-28_10-57.png

Step 3: Save and check the result.

For the search page, you can do the same as above.

 

Please let me know if it works as expected!

Best regards!

Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants


If our suggestion works for you, please give it a Like or mark it as a Solution!


Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com