New Shopify Certification now available: Liquid Storefronts for Theme Developers

Help with liquid code to only show a button at order confirmation if work in product title

JamoDesigns
Tourist
5 1 0

Hi there,

 

I know this has been done but wonder if anyone can help. I have a yarn store and sell patterns. I have the below code from a site called ravelry to it will take the customer to add the pattern they have bought to their raverly library (it is a knitting thing)

 

The code works great. What I am having trouble with it getting it only to appear if one of the items bought has download in the variant title or product title (could be multiple items to check, but only want the button to appear once.

 

If anyone has any ideas on how to do the for loop as we have tried loads of different options but nothing works.

 

So this is the code for the button which I know works...

 

<script>
Shopify.Checkout.OrderStatus.addContentBox('<h2>Ravelry library</h2>',
'<p>' +
'Your order includes pdf files available via Ravelry' +
'</p>' +
'<span class="sdd-checkout-item-button">' +
'<form action="https://www.ravelry.com/shopify/89997/add_to_library" method="post">' +
'<input type="hidden" name="customer_url" value="{{order.order_status_url}}" />' +
'<input type="hidden" name="email" value="{{checkout.email}}" />' +
'<input type="hidden" name="order_number" value="{{checkout.order_number}}" />' +
'<input type="submit" value="add pattern(s) to your ravelry library" />' +
'</form>' +
'</span>');
</script>

 

Thank you so much of you can help.

 

Jamo

Replies 5 (5)
gr_trading
Shopify Partner
1406 131 151

Hi @JamoDesigns 

 

What do you mean by,

 

only want the button to appear once.

 

Can you clarify?

 

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee
JamoDesigns
Tourist
5 1 0

Hi thanks for responding.

 

Meant if the person had bought 4 patterns, don't want the button to appear 4 times if in a loop.

 

Thanks,

 

Jamo

gr_trading
Shopify Partner
1406 131 151

Request you to try with below code in the additional script.

 

{% for item in order.line_items %}
{% if item.title contains "download"  %}
<script>
Shopify.Checkout.OrderStatus.addContentBox('<h2>Ravelry library</h2>',
'<p>' +
'Your order includes pdf files available via Ravelry' +
'</p>' +
'<span class="sdd-checkout-item-button">' +
'<form action="https://www.ravelry.com/shopify/89997/add_to_library" method="post">' +
'<input type="hidden" name="customer_url" value="{{order.order_status_url}}" />' +
'<input type="hidden" name="email" value="{{checkout.email}}" />' +
'<input type="hidden" name="order_number" value="{{checkout.order_number}}" />' +
'<input type="submit" value="add pattern(s) to your ravelry library" />' +
'</form>' +
'</span>');
</script>
{% endif %}
{% endfor %}

 

Hope this will help...

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee
JamoDesigns
Tourist
5 1 0

Hi thanks,

 

Sorry did not work. With liquid just wondering if the if will be case sensitive. Will do a few tests when I get some free time.

 

Thanks for your help.

 

Jamo

gr_trading
Shopify Partner
1406 131 151

Let me know once you are done with your test.

 

We can fix this if want?

For any custom development WhatsApp or connect at Email ID: gr.trading15@gmail.com for quick consultation. | YouTube Videos
To support Buy Me a Coffee