Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

price displayed sometimes puts 'USD' after it , sometimes does not .

price displayed sometimes puts 'USD' after it , sometimes does not .

ericnickus
Tourist
8 0 1

In my product grid display, I have some items saying USD after the price, and some not.  Also it does not force it to display to two decimal places, sometimes the price comes out as '7.1', even though i put the money modifier.   It just does this in the theme basically ( I know a lot of code to display the price lol):


<div class="grid-product__meta">
<div class="grid-product__title grid-product__title--{{ settings.type_product_style }}">{{ product.title }}</div>
{%- if settings.vendor_enable -%}
<div class="grid-product__vendor">{{ product.vendor }}</div>
{%- endif -%}

{% comment %}Start automatically added Judge.me widget{% endcomment %}
{% render 'judgeme_widgets', widget_type: 'judgeme_preview_badge', concierge_install: true, product: product %}
{% comment %}End automatically added Judge.me widget{% endcomment %}

{%- assign unit_lowercase = product.metafields.custom.unit | downcase -%}
<div class="grid-product__price">
{%- if on_sale -%}
<span class="visually-hidden">{{ 'products.general.regular_price' | t }}</span>
<span class="grid-product__price--original">{{ product.compare_at_price | money }}</span>
<span class="visually-hidden">{{ 'products.general.sale_price' | t }}</span>
{%- endif -%}
{%- if product.price_varies -%}
{%- assign price = product.price_min | money -%}
{{ 'products.general.from_text_html' | t: price: price }}
{%- else -%}
{% if unit_lowercase == 'box' or unit_lowercase == 'piece' %}
{{ product.metafields.custom.sq_ft_price }}
{% else %}
{{ product.price | times: 100 | round | divided_by: 100 | money_with_currency }}
{% endif %}
{% endif %}

{%- if unit_lowercase == 'piece' -%}
/ Piece
{%- endif -%}

{%- if on_sale -%}
{%- if settings.product_save_amount -%}
{%- if settings.product_save_type == 'dollar' -%}
{%- capture saved_amount -%}{{ product.compare_at_price | minus: product.price | money }}{%- endcapture -%}
{%- else -%}
{%- capture saved_amount -%}{{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round }}%{%- endcapture -%}
{%- endif -%}
<span class="grid-product__price--savings">
{{ 'products.general.save_html' | t: saved_amount: saved_amount }}
</span>
{%- endif -%}
{%- endif -%}

{%- assign product_variant = product.selected_or_first_available_variant -%}
{%- if product_variant.unit_price_measurement -%}
<div class="product__unit-price">
{%- capture unit_price_base_unit -%}
{%- if product_variant.unit_price_measurement -%}
{%- if product_variant.unit_price_measurement.reference_value != 1 -%}
{{ product_variant.unit_price_measurement.reference_value }}
{%- endif -%}
{{ product_variant.unit_price_measurement.reference_unit }}
{%- endif -%}
{%- endcapture -%}

{{ product_variant.unit_price | money }}/{{ unit_price_base_unit }}
</div>
{%- endif -%}
</div>

 

 

So I do know what most of it is doing ,but still having a time figuring this out .   Thanks for any tips, or suggestions. 

 

Cheers, 

Eric Nickus

 

Reply 1 (1)

ericnickus
Tourist
8 0 1

Sorry, I did edit the code to be more readable , but it made it like that , how about this 

      <div class="grid-product__meta">
        <div class="grid-product__title grid-product__title--{{ settings.type_product_style }}">{{ product.title }}</div>
            {%- if settings.vendor_enable -%}
                <div class="grid-product__vendor">{{ product.vendor }}</div>
            {%- endif -%}
        
           {% comment %}Start automatically added Judge.me widget{% endcomment %}
           {% render 'judgeme_widgets', widget_type: 'judgeme_preview_badge', concierge_install: true, product: product %}
           {% comment %}End automatically added Judge.me widget{% endcomment %}

           {%- assign unit_lowercase = product.metafields.custom.unit | downcase -%}   
           <div class="grid-product__price">
           {%- if on_sale -%}
              <span class="visually-hidden">{{ 'products.general.regular_price' | t }}</span>
              <span class="grid-product__price--original">{{ product.compare_at_price | money }}</span>
              <span class="visually-hidden">{{ 'products.general.sale_price' | t }}</span>
          {%- endif -%}
          {%- if product.price_varies -%}
              {%- assign price = product.price_min | money -%}
              {{ 'products.general.from_text_html' | t: price: price }}
          {%- else -%}
              {% if unit_lowercase == 'box' or unit_lowercase == 'piece' %}
                  {{ product.metafields.custom.sq_ft_price }}
              {% else %}
                  {{ product.price | times: 100 | round | divided_by: 100 | money_with_currency }}
              {% endif %}
          {% endif %}

          {%- if unit_lowercase == 'piece' -%}
              / Piece
          {%- endif -%}

              {%- if on_sale -%}
                  {%- if settings.product_save_amount -%}
                  {%- if settings.product_save_type == 'dollar' -%}
                  {%- capture saved_amount -%}{{ product.compare_at_price | minus: product.price | money }}{%- endcapture -%}
              {%- else -%}
                  {%- capture saved_amount -%}{{ product.compare_at_price | minus: product.price | times: 100.0 | divided_by: product.compare_at_price | round }}%{%- endcapture -%}
              {%- endif -%}
              <span class="grid-product__price--savings">
                  {{ 'products.general.save_html' | t: saved_amount: saved_amount }}
              </span>
          {%- endif -%}
      {%- endif -%}

          {%- assign product_variant = product.selected_or_first_available_variant -%}
          {%- if product_variant.unit_price_measurement -%}
            <div class="product__unit-price">
              {%- capture unit_price_base_unit -%}
                {%- if product_variant.unit_price_measurement -%}
                  {%- if product_variant.unit_price_measurement.reference_value != 1 -%}
                    {{ product_variant.unit_price_measurement.reference_value }}
                  {%- endif -%}
                  {{ product_variant.unit_price_measurement.reference_unit }}
                {%- endif -%}
              {%- endcapture -%}

              {{ product_variant.unit_price | money }}/{{ unit_price_base_unit }}
            </div>
          {%- endif -%}
        </div>