ievavi Posted June 3, 2021 Share Posted June 3, 2021 31 minutes ago, paul2009 said: See: https://www.sqspthemes.com/blog/how-to-reformat-product-price-in-squarespace Thanks for bringing attention to this resource. What if reformatting needs to be from 15,000.00 to 15,000 (so still keeping the comma in between) ? Link to comment
ievavi Posted June 4, 2021 Share Posted June 4, 2021 Site URL: https://rocksforlife.com Could anyone help me out removing two last zeroes from product price? Example: 15,000.00 to 15,000 (so still keeping the comma in between) The code I used (and which is not achieving my desired result): <script src="https://cdn.jsdelivr.net/.../ready@1.4.0/dist/ready.umd.js"></script> <script>!function(){function reformatPrice(price){var priceClone=price.cloneNode(!0);function reformat(){priceClone.innerHTML=price.innerHTML;var target=priceClone.querySelector(".sqs-money-native")||priceClone,textNode=priceClone.querySelector(".sqs-money-native");target.textContent.length>1?target.textContent=format(target.textContent):textNode&&(textNode.textContent=format(textNode.textContent))}function format(text){return text.replace(",","").replace(/\.\d{2}/,"")}function watch(){var observer;new MutationObserver(reformat).observe(price,{childList:!0})}priceClone.classList.add("product-price-clone"),price.parentNode.insertBefore(priceClone,price.nextElementSibling),price.style.display="none",reformat(),watch()}ready(".product-price:not(.product-price-clone),.original-price:not(.product-price-clone)",reformatPrice)}();</script> Link to comment
paul2009 Posted June 4, 2021 Share Posted June 4, 2021 (edited) Update: Please note that 'pricing' answers provided earlier than 23 August 2022 no longer function as intended. This is due to a Squarespace update on this date. Edited September 15, 2023 by paul2009 ievavi 1 About me: I've been a SQSP User for 18 yrs. I was invited to join the Circle when it launched in 2016. I have been a Circle Leader since 2017. I don't work for Squarespace. I value honesty, transparency, diversity and good design ♥. Work: I founded and run SF.DIGITAL, building Squarespace Extensions to supercharge your commerce website. Content: Views and opinions are my own. Links in my posts may refer to SF.DIGITAL products or may be affiliate links. Forum advice is free. You can thank me by clicking one of the feedback emojis below. Coffee is optional. Link to comment
sophclaud Posted September 15, 2023 Share Posted September 15, 2023 Hi there, I am having the same issue! Would like to get rid of the decimal .00 on my product page! I tried the codes provided above and no luck! Here is the link to my site. https://rooknit.com/shop Link to comment
creedon Posted September 15, 2023 Share Posted September 15, 2023 2 hours ago, sophclaud said: Would like to get rid of the decimal .00 on my product page! Please see the following. Let us know how it goes. Find my contributions useful? Please like, upvote, mark my answer as the best ( solution ), and see my profile. Thanks for your support! I am a Squarespace ( and other technological things ) consultant open for new projects. Link to comment
toddjames Posted January 22 Share Posted January 22 Hi, I've spent ages figuring this out for my site. So thought that you'd like the code too. 1. To remove the decimals from pricing in 7.1. e.g. so that £100.00 becomes £100 add the below script to your footer using code injection: <script> document.addEventListener("DOMContentLoaded", function() { // Selecting the price elements var priceAmounts = document.querySelectorAll('.pricing-plan-price-amount'); priceAmounts.forEach(function(price) { var text = price.textContent; var updatedText = text.split('.')[0]; // This removes the decimal part price.textContent = updatedText; }); // Keeping the billing period text intact var billingPeriods = document.querySelectorAll('.pricing-plan-price-billing-period'); billingPeriods.forEach(function(period) { // We don't need to change this, but we include it to avoid accidentally altering it var text = period.textContent; period.textContent = text; }); }); </script> 2. To remove the comma from pricing. E.g. so that £1,000 becomes £1000 add the below script to your footer using code injection: <script> document.addEventListener("DOMContentLoaded", function() { // Selecting the price elements var priceAmounts = document.querySelectorAll('.pricing-plan-price-amount'); priceAmounts.forEach(function(price) { var text = price.textContent; var updatedText = text.split('.')[0]; // Removes the decimal part updatedText = updatedText.replace(/,/g, ''); // Removes commas price.textContent = updatedText; }); // Keeping the billing period text intact var billingPeriods = document.querySelectorAll('.pricing-plan-price-billing-period'); billingPeriods.forEach(function(period) { // No change needed here var text = period.textContent; period.textContent = text; }); }); </script> Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment