How to add Barcode to email notifacations?

Dsky612
Shopify Partner
7 0 0

This is the code.

<ul>  
    {% for line in subtotal_line_items %} 
    <li>
        <img src="{{ line | img_url: 'thumb' }}" /> {{ line.quantity }}x {{ line.title }} {% if line.sku != "" %}(SKU: {{line.sku}}){% endif %} for {{ line.price | money }} each
        (
        {% if line.variant.barcode %}
        {{ line.variant.barcode }}
        {% else %}
        no barcode!
        {% endif %}
        )
    </li>
     {% endfor %} 
</ul>

 

But it doesn't work.

 

Can anyone tell me how to solve it?

0 Likes
KarlOffenberger
Shopify Partner
1868 184 819

Hi Dsky

Not sure as I haven't tried this, but I am going to guess your product has variants and you are trying to access the variant on line_item.

Instead go through line_item.product.variants

{% for variant in line.product.variants %}
  ..
{% endfor %}

Hope that helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Dsky612
Shopify Partner
7 0 0

Thank you for reply.

 

I can get the barcode go through line_item.product.variants.

But some product have more than one variant. And they have different barcode.

If I use line_item.product.variants, I don't know which is the one I need. 

Because I also can't get the line_item.variant

 

0 Likes
KarlOffenberger
Shopify Partner
1868 184 819

So just match the variant in the line.product.variants loop with the line.variant_id.

{% for variant in item.product.variants %}
{% if item.variant_id == variant.id %}
  {{ variant.barcode }}
{% endif %}
{% endfor %}

 

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
KarlOffenberger
Shopify Partner
1868 184 819

Something like:

{% for variant in item.product.variants %}
{% if item.variant_id == variant.id %}
  {{ variant.barcode }}
{% endif %}
{% endfor %}

Hope that helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Dsky612
Shopify Partner
7 0 0

line.variant_id , line.variant , line.variant.barcode , line.variant.image
I can't get anyone of these.

0 Likes
KarlOffenberger
Shopify Partner
1868 184 819

Hi, I am assuming you are modifying the order confirmation email template.

I just did the same and modified mine in a dev store adding the above bit of code (replaced typo item for line since that's the property available in the template).

When you use preview it won't work because the fake order used in preview doesn't have a line item with variant_id. However, if you create an order and have the order confirmation notification active, the sent email will contain the barcode for the line items' variant.

Hope that helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
Dsky612
Shopify Partner
7 0 0

I am really modifying the order confirmation email template.

OK. I konw.

So how do I make sure the real order is correct? Is there a way to test it?

0 Likes
KarlOffenberger
Shopify Partner
1868 184 819

Simply create a draft order (or order, doesn't really matter) with a product variant that has barcodes. Pick a customer (ideally yourself or some test customer with an email that you can access / check the inbox). Click Mark as paid, Choose Cash on Delivery or whatever and that's that.

In the order timeline for that order, you should see that an order confirmation email was sent. You also have the possibility to resend it. Now you can edit your email template and resend that test orders' confirmation email over and over until you have it the way youwant.

Hope that helps!

Liked this post? You might also like our fantastic upsell apps Candy Rack, Last Upsell post-purchase and Candy Cart or offer free gifts with Gift Box. All made with ❤️  and care by Digismoothie
0 Likes
Dsky612
Shopify Partner
7 0 0

That's OK now!

Thanks for your help!
 

0 Likes