Search code examples
themesshopifyshopify-template

Shopify Theme - Discount percentage always at 0 (product page)


The discount percentage of my products is always equal to 0%

This problem occurred with the new store theme that I uploaded

Please check the joined image: https://image.noelshack.com/fichiers/2019/30/1/1563820267-capture.png)

I have tried to check the code inside product-template.liquid file but didn't find anything wrong.

Here is the part of the code responsible for generating this discount

<span class="save_discount_pro">
              {% if current_variant.compare_at_price > current_variant.price %}
                {% if settings.show_discount_amount == 'percent_save' %}
                <span class="per_discount">
                  {% comment %}
                    {% endcomment %}
                  {% assign money_pro_format = shop.money_format | strip_html | json %}

                  {% if money_pro_format contains "${{amount_no_decimals}}" or money_pro_format contains "${{amount_no_decimals_with_comma_separator}}" %}
                  {{ current_variant.compare_at_price  | minus: current_variant.price  | times: 100.0 | divided_by: current_variant.compare_at_price | times: 100 | money_without_currency | replace:",","." | replace: '.0', '' }}{{ 'products.product.on_save' | t }}
                  {% elsif money_pro_format contains "${{amount_with_comma_separator}}" %}
                  {{ current_variant.compare_at_price  | minus: current_variant.price  | times: 100.0 | divided_by: current_variant.compare_at_price | money_without_currency | replace:",","."  | times: 100 | replace: '.0', '' }}{{ 'products.product.on_save' | t }}
                  {% else %}                  
                  {{ current_variant.compare_at_price  | minus: current_variant.price  | times: 100.0 | divided_by: current_variant.compare_at_price  | money_without_currency | times: 100 | replace: '.0', ''}}{{ 'products.product.on_save' | t }}
                  {% endif %}
                  </span>

could detect anything wrong with the code?

Best regards,


Solution

  • It seems likely that in your Shopify admin, under 'Store Currency' (Settings->General->Store Currency->Change formatting), the values don't match the values in your code.

    Do the values in your admin start with '$'? If so, could you omit them from your code. Eg. Instead of 'if money_pro_format contains "${{amount_no_decimals}}"', use 'if money_pro_format contains "{{amount_no_decimals}}"'