Digital Vs. Physical Product Liquid Code for Confirmation Email

Hey there!

I am trying to update the out-of-the-box Order Confirmation email to display a specific message if a customer purchases a digital product only OR a specific message if a customer purchases a digital product and a physical product.

Has anyone added this kind of customization to their Order Confirmation email before and if so, what code did you use?

Thanks!

Hello! Were you ever able to figure this out, i see the post is from awhile ago but I have the exact same question - looking for code to copy & modify. Thanks so much if you’re able to provide!

Hey guys - issue is there’s no way to check for whether a product is digital or not in Liquid, but there are a few options:

  1. Check line_item requires_shipping
  2. Interrogate the order’s shipping methods to see if it didn’t need shipping
  3. Use a metafield that you can set to reflect which products are digital, and check that per item in the cart.

Whatever way you choose, use an {% if condition %} to show one message or the other.

Example, may or may not work:

{% assign has_digital_and_physical_products = false %}
{% assign count_physical_items = cart.items | map: ‘requires_shipping’ | where: true %}

{% if count_physical_items > 0 and count_physical_items != cart.item_count %}
{% assign has_digital_and_physical_products = true %}
{% endif %}

or probably easier to use:
{% assign has_digital_products = false %}
{% assign has_physical_products = false %}
{% for item in cart.items %}
{% if item.requires_shipping %}
{% assign has_physical_products = true %}
{% else %}
{% assign has_digital_products = true %}
{% endif %}
{% endfor %}

{% if has_digital_products and has_physical_products %}
Your package is on its way! Also look for an email.
{% elsif has_digital_products %}
Check your email!
{% else %}
Your package is on its way!
{% endif %}