Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
My code from the Legacy version of Order Printer is broken, but I would like to achieve these results. Is this possible without using IF ELSE? Here are the conditions.
If the customer is using Shopify payments, then display the Credit Card Brand.
If all other payment methods, Paypal, Affirm, Gift Card, then display those gateways.
Is this possible? My Legacy code did this, but in the new Order Printer version, it shows "shopify_payments" with the same code.
Solved! Go to the solution
This is an accepted solution.
I figured out my own solution by asking ChatGPT. This is working well for me now. The formatting is a bit sloppy with the first line not correctly indented.
{% assign shopify_payments_gateway = "shopify_payments" %}
{% assign payment_method_printed = false %}
{% for transaction in order.transactions %}
{% if transaction.gateway == shopify_payments_gateway %}
{{ transaction.payment_details.credit_card_company }}
{% assign payment_method_printed = true %}
{% break %}
{% endif %}
{% endfor %}
{% if payment_method_printed == false %}
{{ transactions[0].gateway_display_name }}
{% endif %}
I am not sure there is a way to accomplish this without the use of if statements. I will admit I'm not 100% certain about that as I haven't needed to mess with transaction lines too frequently.
Here is an example code snippet that does what your asking using if statements. Obviously it would need to be modified to fit your specific template, but it might be a good jumping off point if no one is aware of a way to accomplish this without the if statements.
<table class="table-tabular" style="margin: 1em 0 0 0;">
<thead>
<th>Payment Method</th>
<th>Amount</th>
<th>Status</th>
</thead>
<tbody>
{% for transaction in transactions %}
{% if transaction.kind != 'authorization' %}
<tr>
<td>
{% if transaction.gateway == 'shopify_payments' %}
{{ transaction.payment_details.credit_card_company }} ending in {{ transaction.payment_details.credit_card_last_four_digits }}
{% else %}
{{ transaction.gateway_display_name }}
{% endif %}
</td>
<td>{{ transaction.amount | money }}</td>
<td>{{ transaction.status }}</td>
</tr>
{% endif %}
{% endfor %}
</tbody>
</table>
It seems that I am stuck with using If-Then statements, which is fine.
However, this code isn't working for me and now a second problem appeared where it won't display correctly if a Credit Card and a Gift Card were both used for the order. It only shows the Credit Card.
This is an accepted solution.
I figured out my own solution by asking ChatGPT. This is working well for me now. The formatting is a bit sloppy with the first line not correctly indented.
{% assign shopify_payments_gateway = "shopify_payments" %}
{% assign payment_method_printed = false %}
{% for transaction in order.transactions %}
{% if transaction.gateway == shopify_payments_gateway %}
{{ transaction.payment_details.credit_card_company }}
{% assign payment_method_printed = true %}
{% break %}
{% endif %}
{% endfor %}
{% if payment_method_printed == false %}
{{ transactions[0].gateway_display_name }}
{% endif %}
Does this code require a certainly level of Shopify plan to work? I have the Shopify Basic plan and this code, when inserted, doesn't seem to produce anything.
I have no idea. Maybe post your code for the Receipt Printer and maybe someone here can help.
We recently spoke with Zopi developers @Zopi about how dropshipping businesses can enha...
By JasonH Oct 23, 2024A big shout out to all of the merchants who participated in our AMA with 2H Media: Holi...
By Jacqui Oct 21, 2024We want to take a moment to celebrate the incredible ways you all engage with the Shopi...
By JasonH Oct 15, 2024