I know Oder printer uses 'IF statement' liquid code in its template, but I'm having a darn of a heckin' time trying to get this one simple piece of code to work with it.
All I'm trying to do is add a cell to my invoice to show a product tag (if the product contains such a tag), but its not working at all. I actually use this very same exact snippet of code on my webs product pages to show special messaging on my product pages, and that works just fine.
But it doesnt seem to want to work with order printer.
<td>{% if product.tags contains 'finalsale' %}ALL SALES FINAL{%- else -%} {% endif %}</td>
Am I doing something wrong here?
<tbody> {% for line_item in line_items %} <tr> <td>{{ line_item.quantity }} x</td> <th>{{ line_item.sku }}</th> <td>{{ line_item.title }}</td> {% if line_item.tax_lines %} <td> {% for tax_line in line_item.tax_lines %} {{ tax_line.price | money }} {{ tax_line.title }}<br/> {% endfor %} </td> {% endif %} <td> {% if line_item.original_price != line_item.price %} <s>{{ line_item.original_price | money }}</s> {% endif %} {{ line_item.price | money }} </td> <td>{% if product.tags contains 'finalsale' %}ALL SALES FINAL{%- else -%} {% endif %}</td> </tr> {% endfor %} </tbody>
yeah, i was going to add it to the footer of the document, but not every item we sell will be 'final sale' which is why i wanted it to be next to every line item (which qualifies). We get too many customer complaints about how they didnt know the item they bought was FINAL SALE because it didn't say so on their packing slip/receipt thats in the box (even thought our product pages state FINAL SALE prior to them buying the item, go figure)
hmmm.....
Perhaps have a look at this.
https://help.shopify.com/en/themes/liquid/objects/line_item
You can use these objects to define the IF statement. You will just need to assign, a value, or name you can query to the final sale items.
im not sure if i follow 100% or understand. So by using the Lineitem objects, would my snippet of code go from:
<td>{% if product.tags contains 'finalsale' %}ALL SALES FINAL{%- else -%} {% endif %}</td>
to:
<td>{% if line_item.product product.tags contains 'finalsale' %}ALL SALES FINAL{%- else -%} {% endif %}</td>
Not sure if im fully understanding the need to use lineitem objects in with this...or maybe im not fully understanding
Almost correct yes.
Sorry if my explanation did not make 100% sense before.
This is the correct code:
{% if line_item.product.tags contains 'finalsale' %}ALL SALES FINAL{%- else -%} {% endif %}
User | Count |
---|---|
11 | |
11 | |
6 | |
5 | |
4 |