Can I remove decimals on a product page with custom css

YB1981
Tourist
15 0 2

Hello,

 

I need to remove the decimals of the price on the product page. So "45,-" instead of 45,00. I only want to do this on some of my product templates and not the whole store. So preferably with custom css on the product page it self. Theme code could also be an option, but not prefered. 

 

Alternatively it could be an option to use superscript to do this. Can that be done with (custom) css?

 

Thanks!

 

Replies 5 (5)

Asad-Mahmood
Explorer
72 11 13

Hi,
This can not be done purely with css 
To change the format of prices for some products you need to modify the code that is displaying prices on product page and add some conditional logic to modify the price format for some specific products

If my solution has been helpful, you can consider supporting me via Buy Me a Coffee.
Hire me: asadmahmood8470@gmail.com
YB1981
Tourist
15 0 2

Ok clear. Is there any possibility that you can provide an example code ?

 

Thanks,

 

Asad-Mahmood
Explorer
72 11 13

Sure I can provide you a sample code

{% if template == 'your-special-product-template-name-here' %}
  {% assign product_price = product.price | divided_by: 100 | round %}
  {{ product_price | money_without_trailing_zeros }}
{% else %}
  {{ product.price | money }}
{% endif %}
If my solution has been helpful, you can consider supporting me via Buy Me a Coffee.
Hire me: asadmahmood8470@gmail.com
YB1981
Tourist
15 0 2

Thank you, so i must place this in the price.liquid? I'm using the Expanse theme.

But i'm not able to get this to work... For now i want to use it in the standaard product template > which name should be "product" > but how can i double check that?

Asad-Mahmood
Explorer
72 11 13

Hi, 

If you want me to further look into this I need to view your theme files and complete guideline on "for which specific products you want to apply this"

If my solution has been helpful, you can consider supporting me via Buy Me a Coffee.
Hire me: asadmahmood8470@gmail.com