Pass Liquid variables to Javascript

Highlighted
New Member
2 0 0

Hi everyone, I'm trying to pass some Liquid variables inside transaction object from order object, how can I do it? Something like that:

 

{% for transaction in order.transactions %}
    	let transaction_amount = {{ transaction.amount }};
       let transaction_gateway {{ transaction.gateway }}
{% endfor %}

 

  

Thanks in advance.

0 Likes
Highlighted
Shopify Expert
866 72 203

Yes, like that. Although if you're looping through transactions, rather than redefine the JS variable each time, I would push them into an array of objects ( let transactions = []; ).

Note: You're missing a semicolon after the 2nd variable declaration.

Note 2: I would make the transaction amount a string, just in case you get some unexpected data, otherwise your script will break. ( let transaction_amount = "{{ transaction.amount }}"; )

Founder of Speed Boostr (Shopify optimization and dev agency).
Creator of Theme Scientist (A/B testing app).
Creator of Order Automator (app that auto tags + fulfills orders, send emails).
Creator of Tip Jar (add a tip button to your store).
Creator of Shopify Analyzer (first performance analysis tool specifically for Shopify sites).
My team also builds custom apps and automated solutions.
Enjoy the adventure!
0 Likes