Why is my additional script not loading on the checkout page?

alexandrosmm
Shopify Partner
1 0 0

Hello,

I have add that script in checkout page:

 

<!-- Send the Item data for each item in the shopping cart -->
<script>
{% for item in order.line_items %}
skroutz_analytics('ecommerce', 'addItem', JSON.stringify({
order_id: '{{ checkout.id }}',
product_id: '{{ item.product.id }}',
name: '{{ item.product.title | escape }}', // Product Name. Required.
price: '{{ item.price | money_without_currency }}',
quantity: '{{ item.quantity }}'
}));
{% endfor %}
</script>

 

Τhe script does not appear on the thank you page. Only if I refresh the thank you page does the script appear

 

I also tried to put the {% for line_item in order.line_items %} in the whole code but it still didn't work. Only when I refreshed the page did it bring results.


Ιf I remove the command {% for item in order.line_items %} and {% endfor %} then the script works normally but  brings an empty result.


what is wrong with the code?

Best regards,
Alex

Replies 0 (0)