Show content in Shipping Confirmation email only if the order has a certain tag?

I want to include a link to complete payment if the order is tagged with “CODiDirect-test” in the Shipping Confirmation email (and if they haven’t completed payment at checkout but that condition is already set up for the order to be tagged “CODiDirect-test”). This is what I have:

{% if customer.orders.order.tags CONTAINS "CODiDirect-test"}
  <table>

  
    
      
        <table>

          
            
              
        {% if payment_terms.type == 'receipt' and payment_terms.next_payment.due_at == nil %}
          {% assign due_date = 'now' %}
        {% else %}
          {% assign due_date = payment_terms.next_payment.due_at | default: nil %}
        {% endif %}
        ## Payment of {{ order.total_outstanding | money }} is due {{ due_date | date: format: 'date' }}
        {% if checkout_payment_collection_url %}
        <table>

  
    
      <table>

        <tr>

          <td>

Pay now

</td>

        </tr>

      </table>
{% endif %}

Everything shows up how I want it to, but I can’t get it to only show on orders with the tag “CODiDirect-test”. What do I need to change?

Thanks!

The condition check should just be {% if order.tags CONTAINS “CODiDirect-test”}

If your already accessing an order object you don’t need to go up through the customer object’s down through the customers all orders object to the returned .order property object.

Off the top of my head with that syntax I’m not sure return object is using with customer.orders.order but I’d think that just gives the first/last order in all of a customers orders which can be causing unintended side effects of “truthiness” making the if condition always true.

Outside of the conditionals you’d want to do a test with some debug outputs like {{ customer.orders.order.tags}}, {{ customer.orders.order.id}} or {{ customer.orders.order.name}} to see what that results are when using that series of object properties: customer.orders.order ; so that your actually confirming how the comparison logic behaves.