Jump to content

Can someone help me change coding to get rid of decimal places in my pricing?

Recommended Posts

Hi. The following Javascript, inserted via footer code injection should do the trick:


<script>
   (function() {
       var prices = document.getElementsByClassName('sqs-money-native');
   var thisPrice;
   var i, I;
   for (i=0, I=prices.length; i<I; i++) {
       thisPrice = prices[i];
       thisPrice.innerHTML = thisPrice.innerHTML.replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, ""); //http://stackoverflow.com/questions/1015402/1015434#1015434
   }
   })();
</script>

I didn't test this throughout your site...just checked a couple pages. Do let me know if this works for you.

-Brandon


If this or any other answer helps you out, please give credit where credit is due: Accept the answer if you're the poster or Up-Vote the answer if you're not the poster. If it didn't help, feel free to inquire further or wait and see what others have to say. Code is provided without any warranty, expressed or implied.

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

Link to comment
  • 3 years later...
  • 8 months later...
On 1/28/2021 at 7:15 AM, Evelina said:

It s for all the products in this shop https://www.moderncharcuterie.co/shop-charcuterie-boards

Thank you!

Add to Code InjectionFooter

<script>
   (function() {
       var prices = document.getElementsByClassName('sqs-money-native');
   var thisPrice;
   var i, I;
   for (i=0, I=prices.length; i<I; i++) {
       thisPrice = prices[i];
       thisPrice.innerHTML = thisPrice.innerHTML.replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, ""); //http://stackoverflow.com/questions/1015402/1015434#1015434
   }
   })();
</script>

 

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
  • 2 weeks later...
  • 2 months later...
16 hours ago, MarikaS said:

@brandon I've also realised that I have to reload my product pages for the .00s to disappear - any idea why that would happen?

Design > Site Styles > Disable Ajax Loading

Email me if you have need any help (free, of course.). Answer within 24 hours. 
Or send to forum message

How to: Setup Password & Share url Insert Custom CSS - Page Header - Upload Custom Font - Upload File - Find Block ID - Contact Customer Care

Link to comment
  • 1 month later...
On 9/1/2016 at 2:59 AM, brandon said:

Hi. The following Javascript, inserted via footer code injection should do the trick:


 

<script>
   (function() {
       var prices = document.getElementsByClassName('sqs-money-native');
   var thisPrice;
   var i, I;
   for (i=0, I=prices.length; i<I; i++) {
       thisPrice = prices[i];
       thisPrice.innerHTML = thisPrice.innerHTML.replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, ""); //http://stackoverflow.com/questions/1015402/1015434#1015434
   }
   })();
</script>
 

I


If this or any other answer helps you out, please give credit where credit is due: Accept the answer if you're the poster or Up-Vote the answer if you're not the poster. If it didn't help, feel free to inquire further or wait and see what others have to say. Code is provided without any warranty, expressed or implied.
 

The code works great until you have to select a variant. Would anybody be able to help in making decimals stay once you select a variant?

Website for the reference: https://rocksforlife.com/our-jewellery/no-1-solitaire-ring-white-gold

All insights are very much appreciated! Maybe @brandon?

Link to comment
On 2/2/2021 at 3:46 PM, tuanphan said:

Add to Code InjectionFooter


<script>
   (function() {
       var prices = document.getElementsByClassName('sqs-money-native');
   var thisPrice;
   var i, I;
   for (i=0, I=prices.length; i<I; i++) {
       thisPrice = prices[i];
       thisPrice.innerHTML = thisPrice.innerHTML.replace(/(\.[0-9]*?)0+$/, "$1").replace(/\.$/, ""); //http://stackoverflow.com/questions/1015402/1015434#1015434
   }
   })();
</script>

 

The code works great until you have to select a variant. Would anybody be able to help in making decimals stay once you select a variant?

Website for the reference: https://rocksforlife.com/our-jewellery/no-1-solitaire-ring-white-gold

All insights are very much appreciated!

Link to comment

See: https://www.sqspthemes.com/blog/how-to-reformat-product-price-in-squarespace

Update: Please note that answers provided earlier than 23 August 2022 no longer function. This is due to a Squarespace update on this date.

Edited by paul2009

About: SQSP User for 17 yrs. Circle Leader since 2017. I value honesty, transparency, diversity and good design ♥.
Work: Founder of SF Digital, building Squarespace Extensions to supercharge your commerce website. 
Content: Links in my posts may refer to SF Digital products or may be affiliate links.
If my advice helped, you can thank me by clicking one of the feedback emojis below. I love coffee too.

Link to comment

Create an account or sign in to comment

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

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.