Exclude Route Product From Quantity Count

JaRet_Watkins
Tourist
9 0 1

Hi everyone!

Our store uses Order Printer to print out the packing list for an order. We also use optional Route insurance that customers can use to protect their shipment.

I'm trying to build something in our invoice that says "There are XX products in this order" so that when we pick and pack orders, we can ensure that we have the correct number of products in the package. However, because some orders have route insurance, this counts as a "product" in the list of products. I'm trying to figure out how to exclude this product from the addition of products.

Here's my code:

{% assign totalProductsOrdered = 0 %}
{% for line_item in line_items %}
    {% assign totalProductsOrdered = totalProductsOrdered | plus: line_item.quantity %}
{% endfor %}

Later in the template I have this:

Total number of items in order: {{ totalProductsOrdered }}

 What I want is to filter out Route insurance as a product in the object totalProductsOrdered. 

Can I do something like this: 

    {% assign totalProductsOrdered = totalProductsOrdered | plus: line_item.quantity | where: line_item.requires_shipping != false %}
0 Likes
Ninthony
Shopify Partner
1798 260 708

I don't know if your code works, but since the Route insurance is a product I would check for the handle in the line_item loop and l would use an unless statement to just not add 1 to the totalProductsOrdered variable. I don't know exactly what the handle is but it would look something like:

 

{% assign totalProductsOrdered = 0 %}
{% for line_item in line_items %}
  {% unless line_item.handle == 'route-insurance' %}
    {% assign totalProductsOrdered = totalProductsOrdered | plus: line_item.quantity %}
  {% endunless %}
{% endfor %}

 

 

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes
JaRet_Watkins
Tourist
9 0 1

Thank you!

That code didn't work but this did:

  {% unless line_item.title contains 'Route' %}
    {% assign totalProductsOrdered = totalProductsOrdered | plus: line_item.quantity %}
  {% endunless %}

This works for me because we'll never have a product title with the word Route.

Thanks again @Ninthony ! 

0 Likes
Ninthony
Shopify Partner
1798 260 708

Not a problem. Like I said I didn't actually know the handle of the product. I would personally suggest using the products handle as opposed to title, only because of case sensitivity and the fact maybe you would have Route in any of your other product titles. Whatever works for you though.

If my solution helped you, please like and accept as solution!
If you'd like to make any edits to your store, please send me a personal message and we can discuss what you'd like to accomplish :D
0 Likes