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

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

JamoDesigns
Tourist
8 1 1

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 6 (6)

gr_trading
Shopify Partner
2045 149 206

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: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
JamoDesigns
Tourist
8 1 1

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
2045 149 206

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: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee
JamoDesigns
Tourist
8 1 1

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
2045 149 206

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: support@grtrading.in for quick consultation. | Shopify Free codes
To support Buy Me a Coffee

traiant
Shopify Partner
3 0 0

Hi Jamo,

 

In case you're still looking for a solution, our digital products app - FileJar has as integration with Ravelry for that final step of displaying the "Add pattern to library" button both on the Thank You page and on the Order status page. The button only gets displayed once, even if multiple designs were purchased.

 

You can find it here:

https://apps.shopify.com/filejar