Custom status page script not working

Solved
Highlighted
Excursionist
48 2 2

Hello,

I want to add a field with a disclaimer when the shipping address is not a certain country (in this example the customer shouldn't be in the US nor in the UK).

I added this code to the script field in settings > checkout

<script>
{% if checkout.shipping_address.country_code != 'UK' and checkout.shipping_address.country_code != 'US' %}
  Shopify.Checkout.OrderStatus.addContentBox(
    '<p>Disclaimer.</p>'
      )
  {% endif %}
</script>

Unfortunately when I do a test order with a shipping address in a country which is not the US or UK, there is still no field being added to the status page after checkout...

0 Likes
Highlighted
Shopify Partner
9 0 0

Hi SachaBC,

 

The only way you would be able to edit the checkout for a custom message such as this, you would need to be on the Shopify Plus plan. There are a couple of workarounds for this though. add a small note to your Shipping rate details at the check out as seen here.

 

 

If helpful then please Like and Accept Solution.
Want to modify or custom changes on store Hire Me.
0 Likes
Highlighted
Shopify Partner
2294 116 352

This is an accepted solution.

@SachaBC 

{% if checkout.shipping_address.country_code != 'UK' and checkout.shipping_address.country_code != 'US' %}

That "and" means the country has to both the UK and the US at the same time which will never happen.

 

Double check if UK is the country code you want.

Isn't GB the country code for United Kingdom? https://en.wikipedia.org/wiki/ISO_3166-2

 

See if the code is even being added , view the actual source code the browser gets (Ctrl+u) and

Also use the browsers developer console to check for any errors (f12 for chrome).

 

The script may be trying to run before the rest of Shopify Javascript is ready in which case you should use an onLoad event, etc

 

You may want to use {% unless %} to invert the not equal to logic (!=)

{% unless checkout.shipping_address.country_code == 'UK' or checkout.shipping_address.country_code == 'US' %}

 

Also be sure to review the similar customization for any insights

https://help.shopify.com/en/manual/orders/status-tracking/customize-order-status/order-status-javasc...

 https://help.shopify.com/en/manual/orders/status-tracking/customize-order-status/show-content-based-...

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes
Highlighted
Excursionist
48 2 2

@PaulNewton with the "and" and the "!=", shouldn't it be if the shipping address is none of the mentioned ones?

I used the ISO code UK only in this example, which wasn't really tested or anything. On my website I use a different list of countries. Thanks for the info tho.

I checked the console for errors and found the mistake. In my <p> tag sentence, I included a ' which ended that line of code. Therefore the code couldn't run.

Thanks for the help!!

0 Likes
Highlighted
Shopify Partner
2294 116 352

with the "and" and the "!=", shouldn't it be if the shipping address is none of the mentioned ones?

Thanks for pointing out that Boolean logic with nots (!=) !  if  not 1 AND not 2 then 3

 

Problem Solved? ✔️Accept and ? Like the solution so you can help others.
Buy me a coffee ☕ paypal.me/paulnewton or donate to eff.org
Confused? Busy? Buy a custom solution paull.newton+shopifyforum@gmail.com
0 Likes