skip to Main Content

I have previously made a financing calculator, so you can see the price if you pay over 10 months. An update has arrived in Shopify, which blocks my scripts.

monthly payment <span class="grafikr-finans-price-10">{{ product.price | divided_by: 10 | money }}</span></p>

$('.grafikr-finans-price-10').text(((price.replace('.','')/10).toFixed(1) + '0 kr.').replace('.',','))

Anyone know how to fix the problem?
You can se the problem here:https://imgur.com/Y4k9amz

You can see the full script here:

<script>
$(document).ready(function() {
  function setprice() {
  
    	  var price = $('#price-field').text().replace(',00 DKK','')
    for (i = 0; i < $('.grafikr-finans-price').length; i++) {
    	$('.grafikr-finans-price').text(price + ' kr.')
    }
    	$('.grafikr-finans-price-10').text(((price.replace('.','')/10).toFixed(1) + '0 kr.').replace('.',','))
  }
  
  setprice()
  
  $('.sod_option').click(function() {
    setTimeout(function() {
      setprice()
    }, 500)
  
  }); 

});
</script>

2

Answers


  1. Chosen as BEST ANSWER

    This work :-)

    <script>
    $(document).ready(function() {
      function setprice() {
      
       	var price = $('#price-field').text().replace(',00 DKK','')
        for (i = 0; i < $('.grafikr-finans-price').length; i++) {
        	$('.grafikr-finans-price').text(price)
        }
        $('.grafikr-finans-price-10').html(
          ((parseInt(price.replace('.','')) / 20).toFixed(1) + '0 kr.').replace('.',',')
        );
      }
      
      setprice()
      
      $('.sod_option').click(function() {
        setTimeout(function() {
          setprice()
        }, 500)
      
      }); 
    	
    });
    </script>


  2. price.replace is going to give you a string, which cannot be divided (hence NaN).

    Try this:

    var price = parseInt($('#price-field').text().replace(',00 DKK',''))
    // snipped...
    $('.grafikr-finans-price-10').text(price/10).toFixed(1)
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search