Conditional pdf attachment to confirmation notification

Solved
Excursionist
19 0 3
Hi there

We’re trying to attach a pdf to our invoices only if a customer buys a certain product.

Is this possible within Shopify or does anyone know a way how to achieve this perhaps with an App?

Thanks,
Evert
0 Likes
Shopify Partner
239 59 69

Hi @greiseve,

 

I understand that you're trying to attach a PDF to your invoices only if a customers buys a certain product.

 

This is possible within Shopify by writing custom code for your Draft order invoice email notification template. The code would look for a particular product within the order and, if found, include the PDF link.

 

This solution works best if you're targeting one or a limited selection of products. However, if you have a lot of products needing unique PDF links, it's probably a better idea to look for an app to solve this.

 

Are you targeting one or multiple products? Does every product being targeted have the same PDF link?

 

If you're willing to describe your use case for this in detail, the community can point you in the right direction.

 

Cheers!

Brian | Shopify Partner | Ecommerce Consultant
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution  
 - Need further assistance? Visit www.BrianAtWork.com

1 Like
Excursionist
19 0 3
Brian

Thanks for the help. Much appreciated.

We have one product category that only requires one pdf link.

I would assume that it’s a if/then (category match) the pdf link is inserted.

Is this fairly easily executed in the script?

Thanks,
Evert
0 Likes
Shopify Partner
239 59 69

@greiseve Yes, it's a fairly simple line of code like an if/then.

 

When you say one product category, and matching for that category – how are you doing the matching or defining the category? By collection, tag, vendor?

Brian | Shopify Partner | Ecommerce Consultant
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution  
 - Need further assistance? Visit www.BrianAtWork.com

1 Like
Excursionist
19 0 3
@BrianAtWork we would use our ‘collections’ as an identifier. So if something matches collection X then we want to display the pdf link.

0 Likes

Success.

Shopify Partner
239 59 69

@greiseve Okay, try this out in your invoice notification template:

 

Notes:

  • Place the code where you want the link to appear.
  • Be sure to replace YOUR_COLLECTION_NAME_GOES_HERE and YOUR_PDF_URL_GOES_HERE

 

 

{% assign show_PDF_link = false %}
{% for line in subtotal_line_items %}
  {% for collection in line.product.collections %}
    {% if collection.title == 'YOUR_COLLECTION_NAME_GOES_HERE' %}
      {% assign show_PDF_link = true %}
    {% endif %}
  {% endfor %}
{% endfor %}
{% if show_PDF_link == true %}
  <p><a href="YOUR_PDF_URL_GOES_HERE">Click here to download your PDF file.</a></p>
{% endif %}

 

Let me know if this solves your problem or if you need further help!

 

Brian | Shopify Partner | Ecommerce Consultant
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Click Accept as Solution  
 - Need further assistance? Visit www.BrianAtWork.com

1 Like
Excursionist
19 0 3
@BrianAtWork thanks so much! I will try this latest by Tuesday when I’m home again. Will let you know if it works!
1 Like
Excursionist
19 0 3
Brian

This worked just fine! I tested it yesterday and now we just need to insert it and fine tune a bit.

Much appreciated! It will make our communication much easier!

Evert
1 Like