Reformat Product Price

Look Demo

Simplify the format of any price. Example: transform “$8.00” into “$8”. This plugin uses code injection and works with the Brine template family.

How To Install

From your Squarespace account, go to Site Code Injection. Copy and paste the code below into the Footer Code Injection box.

<!-- Reformat Product Price (15,000.00 -> 1500) --> 
<!-- Author: Dmitry Kiselyov @_dmitrykiselyov --> 
<script src="https://cdn.jsdelivr.net/gh/ryanmorr/ready@1.2/dist/ready.min.js"></script>
<script>
(function() {
  ready('.product-price:not(.product-price-clone)', reformatPrice);
  function reformatPrice(price) {
    var priceClone = price.cloneNode(true);
    priceClone.classList.add('product-price-clone');
    price.parentNode.insertBefore(priceClone, price.nextElementSibling);
    price.style.display = 'none';
    function reformat() {
      priceClone.innerHTML = price.innerHTML;
      var target = priceClone.children[0] || priceClone;
      target.textContent = target.textContent.replace(',', '').replace(/\.\d{2}/, '');
    }
    function watch() {
      var observer = new MutationObserver(reformat);
      observer.observe(price, { childList: true });
    }
    reformat();
    watch();
  }
})();
</script>
<!-- end Reformat Product Price -->

Customize

You do not need to change any of the values or properties.

Notes

No notes.

CommerceMoov Labs