Only show color swatches if more than two colors

Hi! We have the color swatches on our products and collection pages but would like to only display the swatches on the collection page when there are more than 1 variant of colours to a product? Because we are also including a separate filtering by colour, we are ending up with one swatch on products that only have one colour. (which is currently turned off at the moment)

{%- liquid

  assign option_name = option.name | downcase
  assign color_swatch_options = "color, colour, couleur" | split: ", "
  assign current_option = "option" | append: option.position
  assign other_options = "option1 option2 option3" | remove: current_option | strip | split: " "

-%}

  

**{{ option.name }}:** {% for value in option.values %}{% if option.selected_value == value %}{{ value }}{% endif %}{% endfor %}

  {% for value in option.values %}
    {%- liquid

      assign image_url = value | handle | append: '.png' | file_url
      assign css_color = value | split: ' ' | last | handle
      assign available = false

    -%}

    
    {%- liquid

      assign available = false

      for variant in product.variants
        unless variant.available
          continue
        endunless

        unless variant[current_option] == value
          continue
        endunless

        unless variant[other_options[1]] == current_variant[other_options[1]]
          continue
        endunless

        unless variant[other_options[2]] == current_variant[other_options[2]]
          continue
        endunless

        assign available = true
      endfor

    -%}

    
    {%- liquid

      for variant in product.variants
        unless variant[current_option] == value
          continue
        endunless

        unless variant[other_options[0]] == current_variant[other_options[0]]
          continue
        endunless

        unless variant[other_options[1]] == current_variant[other_options[1]]
          continue
        endunless

        if variant.image
          assign variant_image_url =  variant.image | img_url: '100x'
        endif
      endfor

      assign checked = ""

      if current_variant[current_option] == value
        assign checked = 'checked="checked"'
      endif

      assign swatch_img = null
      assign swatch_color_name = value | handle | append: '.png'

      if images[swatch_color_name] != blank
        assign swatch_img = swatch_color_name | file_url
      endif

    -%}

    {% capture radio_button %}
      
    {% endcapture %}

    {% capture sold_out_image %}
      
    {% endcapture %}

    {% capture regular_swatch %}
      

        {{ radio_button }}

        
      

    {% endcapture %}

    {% capture color_swatch %}
      

        {{ radio_button }}

        
      

    {% endcapture %}

    {% if show_color_swatches and color_swatch_options contains option_name %}
      {{ color_swatch }}
    {% else %}
      {{ regular_swatch }}
    {% endif %}
  {% endfor %}

I believe the Dawn theme does it by wrapping the variant selects/swatches in the following unless statement:

{%- unless product.has_only_default_variant -%}
Your code here
{%- endunless -%}