Jump to content
Search In
  • More options...
Find results that contain...
Find results in...
Advanced Search
  • 0

How to remove trailing decimal .00's from product pricing


MarikaS

Question

Hi there. I use the Adirondack template for my site and am wanting to remove the trailing decimal 00's from my pricing.

For example I want $249.00 to display as $249.

Any idea how to make this happen? Any help would be much appreciated, thanks!

Link to post
  • Answers 11
  • Created
  • Last Reply

Top Posters For This Question

Top Posters For This Question

Popular Posts

You can do it with the code that @brandon provided here: http://squarespace.cloud.answerhub.com/questions/152145/can-someone-help-me-change-coding-to-get-rid-of-de.html  

Thank you so much @paul2009 and @brandon. Worked a treat!

Good find @paul2009. That's an example of code I don't even remember writing. One time I went looking for a coding solution I couldn't solve, and was happy when I found it on Answers. Then I realized

11 answers to this question

Recommended Posts

  • 0

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company helping Squarespace users by building the features that Squarespace didn't include.
Explore our range of Squarespace Extensions, including the Wishlist, and Datepicker Extension or book a Squarespace Expert for 1:1 help. Note that links in my posts may be affiliate links.

Link to post
  • 0

Good find @paul2009. That's an example of code I don't even remember writing. One time I went looking for a coding solution I couldn't solve, and was happy when I found it on Answers. Then I realized it was my own answer...

If a response helped you out, send a 'Like' 👍 (bottom-right) and/or 'Upvote' vote.jpg.c260784ece77aec852b0e3049c77a607.jpg (top-left)

Link to post
  • 0

Been there too @Brandon!

The Community team have now imported the old Answers post 👍

 

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company helping Squarespace users by building the features that Squarespace didn't include.
Explore our range of Squarespace Extensions, including the Wishlist, and Datepicker Extension or book a Squarespace Expert for 1:1 help. Note that links in my posts may be affiliate links.

Link to post
  • 0

Thanks @brandon and @paul2009 for this code! It works perfectly when I first save it in the foot code injection, but as soon as I refresh a page, it reverts to the normal pricing with decimals again. I wonder if it's because our prices are in £ rather than $. I've tried swapping the currencies out in the code but I really don't know what I'm doing! Any ideas how I could get it to work?

Here's an example of what I'm working with: https://ellishampers.co.uk/hampers/magnificent-n8-the-marvel

 

UPDATE:

Just checked that the above linked worked and the decimals had disappeared! Tried in incognito and they came back again. It seems that if I refresh the page the code works, but the first time I load it the decimals are always there. In normal browsing (not incognito), the same applies but every time you load the page, you also see the decimals briefly before they disappear. Worth putting the code in the header for this or is that something that could go wrong?

Thank you! 😊

Edited by EllisCo
Link to post
  • 0

The code was written in 2016 and like many of the older code samples provided on forums, it therefore understandably doesn’t take into account the introduction of Ajax on many Squarespace templates since that time. Turning off Ajax in Site Styles will fix this but it’s just a workaround. A better solution is to replace

(function() {

with

window.Squarespace.onInitialize(Y, function() {

If like me you’d like to understand why, I wrote an explanation here: https://sf.digital/squarespace-solutions/why-doesnt-my-code-work-until-i-refresh-the-page

Edited by paul2009

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company helping Squarespace users by building the features that Squarespace didn't include.
Explore our range of Squarespace Extensions, including the Wishlist, and Datepicker Extension or book a Squarespace Expert for 1:1 help. Note that links in my posts may be affiliate links.

Link to post
  • 0

Hi, thank you very much for this solution, I've found this to work great for me as well apart from a single instance when I choose two variables of a product to add to cart - such as a size and a color. When two variables are chosen, suddenly the two decimals appear again. Any idea why that might be and if there's a way to solve this?

Link to post
  • 0

Thanks for the link @JiriWranovsky; I now see what you're referring to.

spacer.png

When a visitor chooses a new variant, Squarespace built-in scripts check the price of the variant. The script then changes the page content to show the new price - even if it is exactly the same as before. The newly updated price includes the fractional element of the price. (There's a longstanding bug here too that removes the sqs-money-native class, but I'll put that to one side because it's not the main issue.)

The code shared above doesn't take account of all this because it's just a 'snippet' of example code to demonstrate how prices can be changed. Like the majority of code you'll find online, it's unsupported and isn't intended for use on a live site.

This particular snippet of code only runs when the page loads. It doesn't run again when the variant changes, which means that the price isn't reformatted to remove the fractional digits. To make it production-ready, the code needs to be restructured so that the function is triggered by several event listeners: on ajax page loading, full page loading and variant dropdown changes. The class in the original code would need to be changed too because of the bug mentioned above. Instead of sqs-money-native, it needs to look for product-price.

As I've said before on this forum, I don't advocate using unsupported code snippets on a production site. If you need robust solutions that won't leave your site vulnerable, I strongly recommend working directly with a Developer that you can trust. There are a number of great developers on this forum who know what they're doing and can be hired for a variety of tasks, from smaller jobs like this to entire sites.

sf-digital-signature-logo-email145.png.46606a2288a2847f44d81b9b7b58f3a5.png
Hi, I'm Paul, founder of SF Digital, a specialist company helping Squarespace users by building the features that Squarespace didn't include.
Explore our range of Squarespace Extensions, including the Wishlist, and Datepicker Extension or book a Squarespace Expert for 1:1 help. Note that links in my posts may be affiliate links.

Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment


×
×
  • Create New...