Have your say in Community Polls: What was/is your greatest motivation to start your own business?

Additional Scripts don't load until page refresh

Additional Scripts don't load until page refresh

toplocations
Tourist
8 0 4

Hi! I've added some custom scripts to my order status page (the Thank You page upon completed checkout), and i'm having issues (everything loads correctly, but only after a page refresh so i don't think it's an error in my code)

 

That being said, if i simply add something like:

 

Shopify.Checkout.OrderStatus.addContentBox('test');

 

it works fine on the initial page load.

 

But if i add what i need in there:

 

<script>
{% for line_item in order.line_items %}
 {% if line_item.product.metafields.custom.sortcode == 2 or line_item.product.metafields.custom.sortcode == 4%}
{% assign sortType = true %}
Shopify.Checkout.OrderStatus.addContentBox('test');
  {% endif %}
{% endfor %}


{% if sortType == true and order.customer.accepts_marketing %}
Shopify.Checkout.OrderStatus.addContentBox('reminders');
{% endif %}
</script>

 

 It doesn't load the content boxes until i refresh the page (unless of course i access the page from orders>Order Status page)

 

So it works with this URL format: https://mysite.com/61052518618/orders/31ebba0e2fa2f7f9ae62d1d6b50ca88b

 

But not with the initial URL: https://mysite.com/checkouts/c/f5d7dac489b8003c4bd56a551dde732c/thank_you

 

Why doesn't it work on the /thank_you page? And is there a way to fix it? Thanks!!

Replies 5 (5)

javed_enduro1
Shopify Partner
4 0 3

Having exact same issue. It is surprising that the support did not post any comment on this. Its been more than 2 months I see.

 

Let me know if you found any solution for this. 

javed_enduro1
Shopify Partner
4 0 3

Hey, 

I just found a workaround for this. Sharing it here so anyone does not run after shopify support. 

 

Just add this script with your script.

<script>
  $(document).ready(function() {
    if (window.location.href.indexOf("thank_you") > -1) {
      setTimeout(
    function()
    {
    location.reload();
    }, 1000);
    } else {
      //alert("It's working");
    }
  });
</script>

chejazi
Shopify Partner
2 0 1

Bumping this. It seems scripts don't load on the Thank you page.

Also, refreshing the Thank you page does not redirect to Order Status page anymore.

javed_enduro1
Shopify Partner
4 0 3

Seems its works fine for me. 

chejazi
Shopify Partner
2 0 1

You're right! It wasn't working in my development store with test purchases, but when I tested it on my production store with real money it worked.

 

Thanks for the reply.