Shopify themes, liquid, logos, and UX
In the Shopify store homepage product collection, how can I display additional price attributes after the price, such as "$12/pcs, $20/kg"?
Solved! Go to the solution
This is an accepted solution.
Hi friend,I can edit the price as you wish as long as there is a clear description or an illustration image, you can try this and let me know if there are any issues.
{% comment %}
Renders a list of product's price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
- show_badges: {Boolean} Renders 'Sale' and 'Sold Out' tags if the product matches the condition (optional)
- price_class: {String} Adds a price class to the price element (optional)
- hide_currency_code: {Boolean} hide currency code regardless of what setting is chosen
Usage:
{% render 'price', product: product %}
{% endcomment %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_compare_at_price = compare_at_price | money
assign money_price = price | money
unless hide_currency_code
if settings.currency_code_enabled
assign money_price = price | money_with_currency
assign money_compare_at_price = compare_at_price | money_with_currency
endif
endunless
if target == product and product.price_varies
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
endif
-%}
<div
class="
price
{%- if price_class %} {{ price_class }}{% endif -%}
{%- if available == false %} price--sold-out {% endif -%}
{%- if compare_at_price > price %} price--on-sale {% endif -%}
{%- if product.price_varies == false and product.compare_at_price_varies %} price--no-compare{% endif -%}
{%- if show_badges %} price--show-badge{% endif -%}
"
>
<div class="price__container">
{%- comment -%}
Explanation of description list:
- div.price__regular: Displayed when there are no variants on sale
- div.price__sale: Displayed when a variant is a sale
{%- endcomment -%}
{%- comment -%}
<div class="price__regular">
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
<span class="price-item price-item--regular{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
</div>
{%- endcomment -%}
<p class="product-price">
{% if compare_at_price > price %}
{% else %}
{{ product.price | money }}
{% if product.metafields.custom.is_per_KG %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{% endif %}
</p>
<div class="price__sale {% if price_second %} price__sale--price-second{% endif %}">
<span class="visually-hidden visually-hidden--inline compare-price-label">
{{- 'products.product.price.regular_price' | t -}}
</span>
<span class="price-item price-item--sale price-item--last{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<span class="visually-hidden visually-hidden--inline regular-price-label">
{{- 'products.product.price.sale_price' | t -}}
</span>
<span class="price__compare-price">
<s class="price-item price-item--regular{% if main_price %} main-comapre-price accent-color-{{ block.settings.compare_price_color }}{% endif %}">
{{ money_compare_at_price }}
</s>
</span>
{% if product.metafields.custom.is_per_KG %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{%- endunless -%}
</div>
<small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
<span class="price-item price-item--last">
<span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
<span aria-hidden="true">/</span>
<span class="visually-hidden"> {{ 'accessibility.unit_price_separator' | t }} </span>
<span>
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
</span>
</span>
</small>
</div>
{%- if show_badges -%}
{% unless hide_sale_badge %}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{% assign percentage_saved = compare_at_price
| minus: price
| times: 100.0
| divided_by: compare_at_price
| floor
| append: '%'
%}
{% capture money_saved %}
{{ compare_at_price | minus: price | money_without_trailing_zeros }}
{% endcapture %}
{% if settings.sale_basge_discount_icon %}{% render 'icon-discount' %}{% endif -%}
<span class="nowrap">
{{-
settings.sale_badge_text
| replace: '[percentage]', percentage_saved
| replace: '[amount]', money_saved
-}}
</span>
</span>
{% endunless %}
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
</div>
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
kindly provide your store URL please and if it is password protected, please share the password as well. Thanks
Best Regards,
HHenry
wholesalecrystalstone.com
You can follow the instruction below:
1. Go to Shopify > Theme > Customize
2. Copy and paste this code on Theme settings > Custom CSS section
div.price__regular {
display: inline-block;
}
.price__container:after {
content: "/pcs";
margin-left: -3px;
}
You can replace pcs with your desired text.
The collection contains multiple products, and each product may have different attributes (for example, one product is in pcs and another in kg).
You can create an 'additional price' product metafield.
add this metafield display after the price display location. For example Dawn theme edit file snippets/price.liquid, paste this at the end of the file before the </div> tag
{% if product.metafields.custom.additionalprice != %}
<span>{{ product.metafields.custom.additionalprice }}</span>
{% endif %}
Text pcs or kg config in metafield.
I’ve already pasted this code, but how do I set up the meta fields? Could you teach me? Thank you!
Hi @David235,
I am from Mageplaza - Shopify solution expert.
To display additional price attributes on the product card, you'll need to modify the HTML of the product card in your theme. Here are some suggestions to help you achieve this:
In the Sections folder, look for the file that controls the product card display of the price.
2. Add Custom Price Attributes :
To display custom price attributes like "$12/pcs" or "$20/kg", you can use product metafields . Here's how to do it:
Create Product Metafields:
Display Metafields in the Template: Now, display these metafields after the price.
<p class="product-price">{{ product.price | money }}</p>
{% if product.metafields.custom.price_per_piece %}
<p class="product-additional-price">{{ product.metafields.custom.price_per_piece }} per pcs</p>
{% endif %}
{% if product.metafields.custom.price_per_kg %}
<p class="product-additional-price">{{ product.metafields.custom.price_per_kg }} per kg</p>
{% endif %}
3. Preview and Test: Save the changes and preview your homepage.
I hope this helps, please leave a comment if you need further instructions !
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
"There is no code like the one in your image."
I am from Mageplaza - Shopify solution expert.
I researched your website and found that the 'price.liquid' file may differ among themes, but the structure of the file is mostly the same. You can press 'Ctrl + F' and type 'price__container' to find it in your 'price.liquid' file and modify it as needed.
I hope this helps, please leave a comment if you need further instructions !
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
It didn't work, I set the meta field and it didn't work.
Hi @David235,
Can you show me the updated metafields and the price.liquid file?
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Product Meta Field Definitions
What to add? I added the code you gave me then I set up the product meta field and added the meta field in the product editor and it's not working either.
Hi @David235
Here are steps to add metafields :
Go to the Shopify Admin Panel:
Choose the Product Resource:
Define a New Metafield:
Save the Metafield Definition.
Add Metafield Values to Products:
Here is the result in product page:
To display the price, simply copy the code below and paste it wherever you want to display it:
{% if product.metafields.custom.price_per_piece %}
<p class="product-additional-price">{{ product.metafields.custom.price_per_piece }} per pcs</p>
{% endif %}
{% if product.metafields.custom.price_per_kg %}
<p class="product-additional-price">{{ product.metafields.custom.price_per_kg }} per kg</p>
{% endif %}
Kindly let me know if it is functioning as intended.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
There's three prices now.
Hi @David235
The metafields are functioning as expected now. Could you please describe how you would like them to be displayed?
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Just add the attribute of the dollar field after the price
I understand your point, therefore, we need to make the necessary adjustments to the metafields:
Apply the appropriate value for the product (per kg or per piece):
And update price.liquid:
<p class="product-price">
{{ product.price | money}}
{% if product.metafields.custom.is_per_kg %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
</p>
Please let me know if it is functioning as intended.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Can't my friend add pcs or kg to the original price?
@David235 ,I want to clarify whether you need to add (kg/pcs) above the price, below the price, or both?
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Add both 2 and feel free to choose whether it's KG or pcs.
Then I set it all up but the kg doesn't show up
Please show me how you set up the metafield for kg, and make sure that you have set the kg value of the product to 'true'.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
I've opened it but the front page doesn't show up
I'm pretty sure that the issue came from the namespace and key due to the difference in names.
<p class="product-price">
{{ product.price | money}}
{% if product.metafields.custom.is_per_kg %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
</p>
The text after 'product.metafields' must match exactly the key of the metafield to function properly.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
You need to change "custom.is_per_kg" to "custom.is_per_KG" in your price.liquid file because your key is
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
yes,kg No KG
But can it be shown on the original price?
Yes, it can be shown wherever you want. Please describe clearly where and when you would like it to be displayed.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
I just want the home page and the original price of the product to be displayed on it, and not to set an extra line for the price, is that ok?
There are three types of prices. If you mean to display it after the product price, it is currently working that way.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Is it okay if I want it formatted like this? Thank you.
Is it okay if I want it formatted like this? Thank you.
@David235Could you provide the full content of your 'price.liquid'? I will customize it for you.
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
{% comment %}
Renders a list of product's price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
- show_badges: {Boolean} Renders 'Sale' and 'Sold Out' tags if the product matches the condition (optional)
- price_class: {String} Adds a price class to the price element (optional)
- hide_currency_code: {Boolean} hide currency code regardless of what setting is chosen
Usage:
{% render 'price', product: product %}
{% endcomment %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_compare_at_price = compare_at_price | money
assign money_price = price | money
unless hide_currency_code
if settings.currency_code_enabled
assign money_price = price | money_with_currency
assign money_compare_at_price = compare_at_price | money_with_currency
endif
endunless
if target == product and product.price_varies
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
endif
-%}
<div
class="
price
{%- if price_class %} {{ price_class }}{% endif -%}
{%- if available == false %} price--sold-out {% endif -%}
{%- if compare_at_price > price %} price--on-sale {% endif -%}
{%- if product.price_varies == false and product.compare_at_price_varies %} price--no-compare{% endif -%}
{%- if show_badges %} price--show-badge{% endif -%}
"
>
<div class="price__container">
{%- comment -%}
Explanation of description list:
- div.price__regular: Displayed when there are no variants on sale
- div.price__sale: Displayed when a variant is a sale
{%- endcomment -%}
<div class="price__regular">
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
<span class="price-item price-item--regular{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
</div>
<p class="product-price">
{{ product.price | money}}
{% if product.metafields.custom.is_per_kg %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
</p>
<div class="price__sale {% if price_second %} price__sale--price-second{% endif %}">
<span class="visually-hidden visually-hidden--inline compare-price-label">
{{- 'products.product.price.regular_price' | t -}}
</span>
<span class="price-item price-item--sale price-item--last{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<span class="visually-hidden visually-hidden--inline regular-price-label">
{{- 'products.product.price.sale_price' | t -}}
</span>
<span class="price__compare-price">
<s class="price-item price-item--regular{% if main_price %} main-comapre-price accent-color-{{ block.settings.compare_price_color }}{% endif %}">
{{ money_compare_at_price }}
</s>
</span>
{%- endunless -%}
</div>
<small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
<span class="price-item price-item--last">
<span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
<span aria-hidden="true">/</span>
<span class="visually-hidden"> {{ 'accessibility.unit_price_separator' | t }} </span>
<span>
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
</span>
</span>
</small>
</div>
{%- if show_badges -%}
{% unless hide_sale_badge %}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{% assign percentage_saved = compare_at_price | minus: price | times: 100.0 | divided_by: compare_at_price | floor | append: '%' %}
{% capture money_saved %}
{{ compare_at_price | minus: price | money_without_trailing_zeros }}
{% endcapture %}
{% if settings.sale_basge_discount_icon %}{% render 'icon-discount' %}{% endif %}<span class='nowrap'>{{ settings.sale_badge_text | replace: '[percentage]', percentage_saved | replace: '[amount]', money_saved }}</span>
</span>
{% endunless %}
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
</div>
Here is updated version, please let me know if it's working correctly
{% comment %}
Renders a list of product's price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
- show_badges: {Boolean} Renders 'Sale' and 'Sold Out' tags if the product matches the condition (optional)
- price_class: {String} Adds a price class to the price element (optional)
- hide_currency_code: {Boolean} hide currency code regardless of what setting is chosen
Usage:
{% render 'price', product: product %}
{% endcomment %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_compare_at_price = compare_at_price | money
assign money_price = price | money
unless hide_currency_code
if settings.currency_code_enabled
assign money_price = price | money_with_currency
assign money_compare_at_price = compare_at_price | money_with_currency
endif
endunless
if target == product and product.price_varies
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
endif
-%}
<div
class="
price
{%- if price_class %} {{ price_class }}{% endif -%}
{%- if available == false %} price--sold-out {% endif -%}
{%- if compare_at_price > price %} price--on-sale {% endif -%}
{%- if product.price_varies == false and product.compare_at_price_varies %} price--no-compare{% endif -%}
{%- if show_badges %} price--show-badge{% endif -%}
"
>
<div class="price__container">
{%- comment -%}
Explanation of description list:
- div.price__regular: Displayed when there are no variants on sale
- div.price__sale: Displayed when a variant is a sale
{%- endcomment -%}
<div class="price__regular">
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
<span class="price-item price-item--regular{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
</div>
<p class="product-price">
{{ product.price | money }}
{% if compare_at_price > price %}
{% else %}
{% if product.metafields.custom.is_per_kg %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{% endif %}
</p>
<div class="price__sale {% if price_second %} price__sale--price-second{% endif %}">
<span class="visually-hidden visually-hidden--inline compare-price-label">
{{- 'products.product.price.regular_price' | t -}}
</span>
<span class="price-item price-item--sale price-item--last{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<span class="visually-hidden visually-hidden--inline regular-price-label">
{{- 'products.product.price.sale_price' | t -}}
</span>
<span class="price__compare-price">
<s class="price-item price-item--regular{% if main_price %} main-comapre-price accent-color-{{ block.settings.compare_price_color }}{% endif %}">
{{ money_compare_at_price }}
</s>
</span>
{% if product.metafields.custom.is_per_kg %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{%- endunless -%}
</div>
<small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
<span class="price-item price-item--last">
<span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
<span aria-hidden="true">/</span>
<span class="visually-hidden"> {{ 'accessibility.unit_price_separator' | t }} </span>
<span>
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
</span>
</span>
</small>
</div>
{%- if show_badges -%}
{% unless hide_sale_badge %}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{% assign percentage_saved = compare_at_price
| minus: price
| times: 100.0
| divided_by: compare_at_price
| floor
| append: '%'
%}
{% capture money_saved %}
{{ compare_at_price | minus: price | money_without_trailing_zeros }}
{% endcapture %}
{% if settings.sale_basge_discount_icon %}{% render 'icon-discount' %}{% endif -%}
<span class="nowrap">
{{-
settings.sale_badge_text
| replace: '[percentage]', percentage_saved
| replace: '[amount]', money_saved
-}}
</span>
</span>
{% endunless %}
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
</div>
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
No way. There are 2 others for the same price.
I sincerely apologize, I forgot to edit 'kg' to 'KG.' Can you please edit it for me ?
As I researched, there are two ways of displaying prices:
Based on your description, I thought you wanted to show '/per (KG/pcs)' after the bottom price. Did I misunderstand you?
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
I just want to display a single price without adding an extra line. It would be better to include "pcs" or "kg" next to the original price.
You want to display it this way, right?
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Here is the updated version
{% comment %}
Renders a list of product's price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
- show_badges: {Boolean} Renders 'Sale' and 'Sold Out' tags if the product matches the condition (optional)
- price_class: {String} Adds a price class to the price element (optional)
- hide_currency_code: {Boolean} hide currency code regardless of what setting is chosen
Usage:
{% render 'price', product: product %}
{% endcomment %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_compare_at_price = compare_at_price | money
assign money_price = price | money
unless hide_currency_code
if settings.currency_code_enabled
assign money_price = price | money_with_currency
assign money_compare_at_price = compare_at_price | money_with_currency
endif
endunless
if target == product and product.price_varies
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
endif
-%}
<div
class="
price
{%- if price_class %} {{ price_class }}{% endif -%}
{%- if available == false %} price--sold-out {% endif -%}
{%- if compare_at_price > price %} price--on-sale {% endif -%}
{%- if product.price_varies == false and product.compare_at_price_varies %} price--no-compare{% endif -%}
{%- if show_badges %} price--show-badge{% endif -%}
"
>
<div class="price__container">
{%- comment -%}
Explanation of description list:
- div.price__regular: Displayed when there are no variants on sale
- div.price__sale: Displayed when a variant is a sale
{%- endcomment -%}
{%- comment -%}
<div class="price__regular">
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
<span class="price-item price-item--regular{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
</div>
{%- endcomment -%}
<p class="product-price">
{{ product.price | money }}
{% if compare_at_price > price %}
{% else %}
{% if product.metafields.custom.is_per_KG %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{% endif %}
</p>
<div class="price__sale {% if price_second %} price__sale--price-second{% endif %}">
<span class="visually-hidden visually-hidden--inline compare-price-label">
{{- 'products.product.price.regular_price' | t -}}
</span>
<span class="price-item price-item--sale price-item--last{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<span class="visually-hidden visually-hidden--inline regular-price-label">
{{- 'products.product.price.sale_price' | t -}}
</span>
<span class="price__compare-price">
<s class="price-item price-item--regular{% if main_price %} main-comapre-price accent-color-{{ block.settings.compare_price_color }}{% endif %}">
{{ money_compare_at_price }}
</s>
</span>
{% if product.metafields.custom.is_per_KG %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{%- endunless -%}
</div>
<small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
<span class="price-item price-item--last">
<span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
<span aria-hidden="true">/</span>
<span class="visually-hidden"> {{ 'accessibility.unit_price_separator' | t }} </span>
<span>
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
</span>
</span>
</small>
</div>
{%- if show_badges -%}
{% unless hide_sale_badge %}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{% assign percentage_saved = compare_at_price
| minus: price
| times: 100.0
| divided_by: compare_at_price
| floor
| append: '%'
%}
{% capture money_saved %}
{{ compare_at_price | minus: price | money_without_trailing_zeros }}
{% endcapture %}
{% if settings.sale_basge_discount_icon %}{% render 'icon-discount' %}{% endif -%}
<span class="nowrap">
{{-
settings.sale_badge_text
| replace: '[percentage]', percentage_saved
| replace: '[amount]', money_saved
-}}
</span>
</span>
{% endunless %}
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
</div>
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
My friend, is it not possible to change the price from the original? Then the price with the discount becomes this.
Here's an extra 12$.
Can I add pcs or kg to the price on my original thread?
Trouble, my friend.
This is an accepted solution.
Hi friend,I can edit the price as you wish as long as there is a clear description or an illustration image, you can try this and let me know if there are any issues.
{% comment %}
Renders a list of product's price (regular, sale)
Accepts:
- product: {Object} Product Liquid object (optional)
- use_variant: {Boolean} Renders selected or first variant price instead of overall product pricing (optional)
- show_badges: {Boolean} Renders 'Sale' and 'Sold Out' tags if the product matches the condition (optional)
- price_class: {String} Adds a price class to the price element (optional)
- hide_currency_code: {Boolean} hide currency code regardless of what setting is chosen
Usage:
{% render 'price', product: product %}
{% endcomment %}
{%- liquid
if use_variant
assign target = product.selected_or_first_available_variant
else
assign target = product
endif
assign compare_at_price = target.compare_at_price
assign price = target.price | default: 1999
assign available = target.available | default: false
assign money_compare_at_price = compare_at_price | money
assign money_price = price | money
unless hide_currency_code
if settings.currency_code_enabled
assign money_price = price | money_with_currency
assign money_compare_at_price = compare_at_price | money_with_currency
endif
endunless
if target == product and product.price_varies
assign money_price = 'products.product.price.from_price_html' | t: price: money_price
endif
-%}
<div
class="
price
{%- if price_class %} {{ price_class }}{% endif -%}
{%- if available == false %} price--sold-out {% endif -%}
{%- if compare_at_price > price %} price--on-sale {% endif -%}
{%- if product.price_varies == false and product.compare_at_price_varies %} price--no-compare{% endif -%}
{%- if show_badges %} price--show-badge{% endif -%}
"
>
<div class="price__container">
{%- comment -%}
Explanation of description list:
- div.price__regular: Displayed when there are no variants on sale
- div.price__sale: Displayed when a variant is a sale
{%- endcomment -%}
{%- comment -%}
<div class="price__regular">
<span class="visually-hidden visually-hidden--inline">{{ 'products.product.price.regular_price' | t }}</span>
<span class="price-item price-item--regular{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
</div>
{%- endcomment -%}
<p class="product-price">
{% if compare_at_price > price %}
{% else %}
{{ product.price | money }}
{% if product.metafields.custom.is_per_KG %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{% endif %}
</p>
<div class="price__sale {% if price_second %} price__sale--price-second{% endif %}">
<span class="visually-hidden visually-hidden--inline compare-price-label">
{{- 'products.product.price.regular_price' | t -}}
</span>
<span class="price-item price-item--sale price-item--last{% if main_price %} main-price accent-color-{{ block.settings.price_color }}{% endif %}">
{{ money_price }}
</span>
{%- unless product.price_varies == false and product.compare_at_price_varies %}
<span class="visually-hidden visually-hidden--inline regular-price-label">
{{- 'products.product.price.sale_price' | t -}}
</span>
<span class="price__compare-price">
<s class="price-item price-item--regular{% if main_price %} main-comapre-price accent-color-{{ block.settings.compare_price_color }}{% endif %}">
{{ money_compare_at_price }}
</s>
</span>
{% if product.metafields.custom.is_per_KG %}
/per kg
{% endif %}
{% if product.metafields.custom.is_per_piece %}
/per pcs
{% endif %}
{%- endunless -%}
</div>
<small class="unit-price caption{% if product.selected_or_first_available_variant.unit_price_measurement == nil %} hidden{% endif %}">
<span class="visually-hidden">{{ 'products.product.price.unit_price' | t }}</span>
<span class="price-item price-item--last">
<span>{{- product.selected_or_first_available_variant.unit_price | money -}}</span>
<span aria-hidden="true">/</span>
<span class="visually-hidden"> {{ 'accessibility.unit_price_separator' | t }} </span>
<span>
{%- if product.selected_or_first_available_variant.unit_price_measurement.reference_value != 1 -%}
{{- product.selected_or_first_available_variant.unit_price_measurement.reference_value -}}
{%- endif -%}
{{ product.selected_or_first_available_variant.unit_price_measurement.reference_unit }}
</span>
</span>
</small>
</div>
{%- if show_badges -%}
{% unless hide_sale_badge %}
<span class="badge price__badge-sale color-{{ settings.sale_badge_color_scheme }}">
{% assign percentage_saved = compare_at_price
| minus: price
| times: 100.0
| divided_by: compare_at_price
| floor
| append: '%'
%}
{% capture money_saved %}
{{ compare_at_price | minus: price | money_without_trailing_zeros }}
{% endcapture %}
{% if settings.sale_basge_discount_icon %}{% render 'icon-discount' %}{% endif -%}
<span class="nowrap">
{{-
settings.sale_badge_text
| replace: '[percentage]', percentage_saved
| replace: '[amount]', money_saved
-}}
</span>
</span>
{% endunless %}
<span class="badge price__badge-sold-out color-{{ settings.sold_out_badge_color_scheme }}">
{{ 'products.product.sold_out' | t }}
</span>
{%- endif -%}
</div>
Mageplaza | Top-Rated Shopify Agency | Trusted by 230,000+ worldwide merchants
If our suggestion works for you, please give it a Like or mark it as a Solution!
Should you have any questions or concerns, feel free to contact us via consultant@mageplaza.com
Hey Community! As we jump into 2025, we want to give a big shout-out to all of you wh...
By JasonH Jan 7, 2025Hey Community! As the holiday season unfolds, we want to extend heartfelt thanks to a...
By JasonH Dec 6, 2024Dropshipping, a high-growth, $226 billion-dollar industry, remains a highly dynamic bus...
By JasonH Nov 27, 2024