Remove / Replace a recommended item if the item is added to the cart

Highlighted
New Member
1 0 0

Hello!

 

In my store I have a collection of recommended items for a variety of products.  What I'm wanting to do is remove a "Recommended Item" from displaying in the list if the item has been added to the cart. I'd also like to add the next item from the collection in it's place.

 

My existing code for the recommended items is below, and I've added the following code to line 6 in hopes that it would work: 'and product.title != line_item.product.title' ( unfortunately, this just removes all recommended items)

 

Thanks for any help / advice!  

 

<div class="cart-item-separator"></div>
<div class="recommended-product-section">
  <h5>{{cart_bicycle_title}} Accessories:</h5>
  <div class="div-block-465">
    {% for product in cart-upsell %}
      {% if product.available and cart_upsell_counter < 4 and product.title != line_item.product.title %}
        <div class="recommended-product-tile">
          <div class="recommemded-product-image">
            {% for image in product.images | limit: 1 %}
              <img src="{{ image | img_url: 'large' }}" alt=""/>
            {% endfor %}
          </div>
          <div class="recommended-product-text"><strong>{{ product.title }}</strong><br/>{{ product.price | money }}</div>
          <form method="post" action="/cart/add">
            <input type="hidden" min="1" type="number" id="quantity" name="quantity" value="1"/>
            <input type="hidden" name="id" value="{{ product.selected_or_first_available_variant.id }}" />
            <input id="" type="submit" class="recommended-product-addtocart" value="Add to cart &#43;" />
          </form>
        </div>
        {% assign cart_upsell_counter = cart_upsell_counter | plus:1 %}
      {% endif %}
    {% endfor %}
  </div>
</div>
 

  

0 Likes