Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hi,
This code:
{% liquid assign reorder_url = '' for line_item in order.line_items assign reorder_url = reorder_url | append: line_item.variant_id | append: ':' | append: line_item.quantity | append: ',' endfor -%} <a href="/cart/{{ reorder_url }}" class="yourbuttonclass" style="background: cornflowerblue; color: white; padding: 10px; text-decoration: none">Reorder</a>
from https://www.froonze.com/blog/how-reorder-products-in-shopify
works to create a REORDER button on the order page of Classic customer accounts.
It generates a URL that includes the variant ID and the quantity and takes you to the checkout so the customer can easily reorder the same things as they had before.
How can I add line item properties to this?
I'm looking forward to feedback on this.
Thank you!
-silver
Not sure if it's possible with cart permalinks as used in that tutorial.
But you can add to cart with URL like
/cart/add.js?id=XXX&quantity=YYY&properties[ZZZ]=AAA&properties[BBB]=CCC&id=...
So the code to start with can be like:
{% capture parameters -%}
{%- for li in order.line_items -%}
id={{ li.variant_id }}&quantity={{ li.quantity }}
{%- for p in li.properties %}
&properties[{{ p.first }}]={{ p.last }}
{%- endfor -%}
{%- endfor -%}
{%- endcapture %}
{% assign url = routes.cart_add_url | append: "?" | append: parameters | url_escape %}
{{ 'Reorder' | link_to: url, class: 'reorder-button' }}
Would need testing though.
Caveats -- if you have file attachments in properties, this most probably would not work.
If you have big orders with long properties, this would not work either since URL will grow too long for browsers to process.
Ideally, you'd need some JS, or, with liquid create a hidden cart form which will be submitted by the reorder button or create this form out of the products list there.
Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024Hey Community! It’s time to share some appreciation and celebrate what we have accomplis...
By JasonH Nov 14, 2024In today’s interview, we sat down with @BSS-Commerce to discuss practical strategies f...
By JasonH Nov 13, 2024