I fixed the issue by changing the code from:
{% comment %}
{{ 'products.product.on_sale' | t }}
{% endcomment %}
{{product.compare_at_price | minus: product.price | times: 100 | divided_by: product.compare_at_price }}% off
to:
{% comment %}
{{ 'products.product.on_sale' | t }}
{% endcomment %}
{{product.**selected_or_first_available_variant**.compare_at_price | minus: product.**selected_or_first_available_variant**.price | times: 100 | divided_by: product.**selected_or_first_available_variant**.compare_at_price }}% off