Hide a collection of Products From Product Recommendations

Solved

Hide a collection of Products From Product Recommendations

DavidCab
Shopify Partner
68 3 22

I am looking to hide a selection of products from my product-recommendation section. I tagged all these products with _hidden so they are automatically added to a collection called "Hidden". I want to hide this collection from my recommendations section. 

 

Here is the code for product-recommendations.liquid not including the schema. i know i need an if statement but don't know where to put it. 

 

 

 

{%- assign use_recommendations = true -%}
{%- assign hand_picked_count = 0 -%}

{%- for block in section.blocks -%}
  {%- if block.settings.product != blank -%}
    {%- assign use_recommendations = false -%}
    {%- assign hand_picked_count = hand_picked_count | plus: 1 -%}
  {%- endif -%}
{%- endfor -%}

{%- capture section_settings -%}
{
  "productId": {{ product.id | json }},
  "useRecommendations": {{ use_recommendations | json }},
  "recommendationsCount": 4
}
{%- endcapture -%}

{%- capture flickity_options -%}
{
  "prevNextButtons": true,
  "pageDots": false,
  "wrapAround": false,
  "contain": true,
  "cellAlign": "center",
  "watchCSS": true,
  "dragThreshold": 8,
  "groupCells": true,
  "arrowShape": {"x0": 20, "x1": 60, "y1": 40, "x2": 60, "y2": 35, "x3": 25}
}
{%- endcapture -%}

<section class="Section Section--spacingNormal" data-section-id="{{ section.id }}" data-section-type="product-recommendations" data-section-settings='{{ section_settings }}'>
  {%- if section.settings.heading != blank -%}
    <header class="SectionHeader SectionHeader--center">
      <div class="Container">
        <h3 class="SectionHeader__Heading Heading u-h3">{{ section.settings.heading | escape }}</h3>
      </div>
    </header>
  {%- endif -%}

  <div class="ProductRecommendations">
    {%- if hand_picked_count > 0 or recommendations.performed and recommendations.products.size > 0 -%}
      <div class="ProductListWrapper">
        <div class="ProductList ProductList--carousel Carousel" data-flickity-config='{{ flickity_options }}'>
          {%- if hand_picked_count > 0 -%}
            {%- for block in section.blocks -%}
              {%- assign product = block.settings.product -%}

              {%- if product != blank -%}
                <div class="Carousel__Cell">
                  {% render 'product-item', product: product, show_product_info: section.settings.show_product_info, show_vendor: section.settings.show_vendor, show_color_swatch: section.settings.show_color_swatch, show_labels: true %}
                </div>
              {%- endif -%}
            {%- endfor -%}
          {%- else -%}
            {%- for product in recommendations.products -%}
              <div class="Carousel__Cell">
                {% render 'product-item', product: product, show_product_info: section.settings.show_product_info, show_vendor: section.settings.show_vendor, show_color_swatch: section.settings.show_color_swatch, show_labels: true %}
              </div>
            {%- endfor -%}
          {%- endif -%}
        </div>
      </div>
    {%- else -%}
      {%- comment -%}Hide the section if there is no recommendations to show{%- endcomment -%}
      <style>
        #shopify-section-{{ section.id }} {
          display: none;
        }
      </style>
    {%- endif -%}
  </div>
</section>

 

 

 

Accepted Solution (1)

DavidCab
Shopify Partner
68 3 22

This is an accepted solution.

I solved myself. 

View solution in original post

Replies 5 (5)

DavidCab
Shopify Partner
68 3 22

This is an accepted solution.

I solved myself. 

janinehaas13
Visitor
2 0 0

can you tell me how you solved this?  I need to do the same thing

DavidCab
Shopify Partner
68 3 22

Fake news. The solution I used didn't work, BUT I stopped using the recommendation engine that is built in and started using a different app for it. it was not cheap. the solution I used before this was just setting whatever products I want as the featured products. 

janinehaas13
Visitor
2 0 0
OKay thanks I appreciate it. I have the recommendations turned off
completely right now which is not good. appreciate the reply!
tbreschi
Visitor
1 0 0

I found this solution on a different thread, tested it and it works for me: https://community.shopify.com/c/technical-q-a/is-there-a-way-to-hide-specific-products-from-the-prod...