Image won't switch when color/size option is change

Hi guys, I’m learning liquid and hopefully anyone can help me with this problem.

Whenever I choose a different color / size, the image won’t update.

This is for the file where you can change color and size.


  

    
    

      # {{ product.title }}
    

    
      {% include 'product-price', variant: current_variant, main_product: true %}
    

    {%- if shop.taxes_included or shop.shipping_policy.body != blank -%}
      
        {%- if shop.taxes_included -%}
          {{ 'products.product.include_taxes' | t }}
        {%- endif -%}
        {%- if shop.shipping_policy.body != blank -%}
          {{ 'products.product.shipping_policy_html' | t: link: shop.shipping_policy.url }}
        {%- endif -%}
      

    {%- endif -%}
    {% capture "form_classes" -%}
      product-form product-form-{{ section.id }} {% if settings.product_page_enable_payment_button and product.has_only_default_variant%} product-form--payment-button-no-variants{% endif %}
    {%- endcapture %}

    {% form 'product', product, class:form_classes, novalidate: 'novalidate' %}
      {% unless product.has_only_default_variant %}
        {% for option in product.options_with_values %}
          
            
            
            {% assign optionName = option.name | downcase %}

            {% assign colorSwatchArr = settings.product_page_option_color_swatch | split: ',' %}
            {% for item in colorSwatchArr %}
              {% assign stripItem = item | strip | downcase %}
              {% if stripItem == optionName %}
                

                  {% for value in option.values %}
                    
                      
                    
                  {% endfor %}
                

                {% break %}
              {% endif %}
            {% endfor %}

            {% assign swatchArr = settings.product_page_option_swatch | split: ',' %}
            {% for item in swatchArr %}
              {% assign stripItem = item | strip | downcase %}
              {% if stripItem == optionName %}
                
                  {% for value in option.values %}
                    
                      {{ value }}
                    
                  {% endfor %}
                

                {% break %}
              {% endif %}
            {% endfor %}
            
          

        {% endfor %}
      {% endunless %}

      
      
      

        

          {% include 'icon-error' %} {{ 'products.product.quantity_minimum_message' | t }}
        

        
          
          
          
        

        
          
          {% if settings.product_page_show_add_to_wishlist %}
            
          {% endif %}
          {% if settings.product_page_show_add_to_compare %}
            
          {% endif %}
        

        
        {% if settings.product_page_enable_payment_button %}
          
            {{ form | payment_button }}
          

        {% endif %}
      

    {% endform %}
    {%- comment -%}
      Live region for announcing updated price and availability to screen readers
    {%- endcomment -%}
    

    {% include 'gp-product-tabs' %}
    {% if staticContent != blank %}
      
        {{ staticContent }}
      

    {% endif %}
    {% unless product == empty %}
      
    {% endunless %}
  

While this is the media:

{%- assign featured_image = product.selected_or_first_available_variant.featured_image | default: product.featured_image -%}

  {% if defaultZoom == 'light-box' %}
    

    {% for image in product.images %}
      {% if image != featured_image %}
        

      {% endif %}
    {% endfor %}
  {% endif %}
  {% if product.images.size > 0 %}
    {% case defaultTemplate %}
      {% when 'gallery-list' %}
        
          - {% if featured_image.alt contains 'youtube' or featured_image.alt contains 'vimeo' %}
              
  {{ 'products.product.video' | t }}

              {% endif %}
          

          {% for image in product.images %}
            {% if image != featured_image %}
              - {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}
                  
  {{ 'products.product.video' | t }}

                  {% endif %}
              
            {% endif %}
          {% endfor %}
        

        
      {% when 'vertical-thumbnail' %}
        

          

            
            {% if featured_image.alt contains 'youtube' or featured_image.alt contains 'vimeo' %}
              
{{ 'products.product.video' | t }}

            {% endif %}
          

          {% for image in product.images %}
            {% if image != featured_image %}
              
                
                {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}
                  
{{ 'products.product.video' | t }}

                {% endif %}
              

            {% endif %}
          {% endfor %}
        

        
          

            

              
            

            {% for image in product.images %}
              {% if image != featured_image %}
                
                  
                

              {% endif %}
            {% endfor %}
          

        

  
  
  
      {% when 'horizontal-thumbnail' %}
        
          

            
            {% if featured_image.alt contains 'youtube' or featured_image.alt contains 'vimeo' %}
              
{{ 'products.product.video' | t }}

            {% endif %}
          

          {% for image in product.images %}
            {% if image != featured_image %}
              
                
                {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}
                  
{{ 'products.product.video' | t }}

                {% endif %}
              

            {% endif %}
          {% endfor %}
        

        
          

            
          

          {% for image in product.images %}
            {% if image != featured_image %}
              
                
              

            {% endif %}
          {% endfor %}
          
           
        

  

      {% when 'no-thumbnail' %}
        
          

            
            {% if featured_image.alt contains 'youtube' or featured_image.alt contains 'vimeo' %}
              
{{ 'products.product.video' | t }}

            {% endif %}
          

          {% for image in product.images %}
            {% if image != featured_image %}
              
                
                {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}
                  
{{ 'products.product.video' | t }}

                {% endif %}
              

            {% endif %}
          {% endfor %}
        

      {% when 'full-screen-multiple-slide' %}
        
          

            
            {% if featured_image.alt contains 'youtube' or featured_image.alt contains 'vimeo' %}
              
{{ 'products.product.video' | t }}

            {% endif %}
          

          {% for image in product.images %}
            {% if image != featured_image %}
              
                
                {% if image.alt contains 'youtube' or image.alt contains 'vimeo' %}
                  
{{ 'products.product.video' | t }}

                {% endif %}
              

            {% endif %}
          {% endfor %}
        

    {% endcase %}
  {% else %}
    {{ 'product-' | append: 1 | placeholder_svg_tag: 'placeholder-svg' }}
  {% endif %}

I guess I have a missing code here and that’s the reason why its not showing up.

Thank you guys :slightly_smiling_face: appreciate all the help if there’ll be :slightly_smiling_face:

And whenever I add this script


it works, but really don’t want the site to refresh everytime