script on variant change

New Member
4 0 0

Hi,

 

To comply with New Zealand Law our site needs to display "+GST" (goods and services tax) to NZ customers after the price of any product on a collection or product page.

 

We have a great script working well except that when on a product page you change an option (variant change) the script does not update as it only runs of page load.

 

Can anyone advise on how to alter the script to run when variants change? 

 

Cheers

 

Andy

 

<script>
  $(window).on('load', function() {
   // $.getJSON('https://ipinfo.io/json', function(data) {
      $.get('https://ip2c.org/?self', function(data) {
 
      if (data.split(';')[1] == "NZ"){
 
 
          $('.money').each(function(i, obj){ // for each money class on the page (there is always a few)
 
            // Check class has any money in it
            if ($(this).is('[data-nzd]')) {
               $(  '<span class="gst">+GST</span>' ).insertAfter($(this));
 
              }
            
 
          });
 
 
}        
      });
   });
</script> 
0 Likes
Shopify Partner
1125 90 137

Hi @andykiwi,

 

Hope you are doing well!

I came across your post and can see that you have added the script on window.onload() function. 

So, the script is running only on page load. You need to add it under the variant selection code.

Hope it helps! Please feel free to reach out for any issue.

Thanks & Regards
Perennial Solution

Problem Solved?✔️Like and Accept the solution that can help others.
Need any help with theme customization or design? Hire us
Email: infoperennialsolution@gmail.com
Skype: infoperennialsolution
1 Like
New Member
4 0 0

Thank you Perennial Solution, 

 

Where I struggle learning to code and to manage this webstore is finding where the responsible code is. I can see this script (which I did not write,  only inherited) needs to be added under the variant selection code but I have no idea what code is responsible for variant selection.

 

Your assistance is much appreciated.

 

Cheers

 

Andy

0 Likes