简体   繁体   中英

Shopify product price divided by 10

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> 

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)

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> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM