4
I created a script to insert a div in my store cart, but it is giving error in the replace function. Would anyone know why ?
var $JQuery = jQuery.noConflict();
$JQuery(function(){
var ValorFreteGratis = 299;
var PrecoTotal = '{{order_total}}';
var QuantoFalta = ValorFreteGratis - PrecoTotal;
var NumeroComVirgula = QuantoFalta.replace(".", ",");
if(PrecoTotal < ValorFreteGratis){
$JQuery('<div class="msg-free_shipping"> <p><span class="warning">EI!!:</span> Comprando mais R$' + NumeroComVirgula.toFixed(2) + ' <span class="restante">você aproveita o <strong>FRETE GRÁTIS</strong> nas compras acima de R$<span class="valor-gratis">' + ValorFreteGratis + '</span></p> </div>').insertAfter('form#cart_update_post');}});
Keeps giving the error: "Uncaught Typeerror: Quantofalta.replace is not a Function"
Probably
QuantoFalta
it’s not a string, maybeundefined
orNaN
. See this way:console.log(typeof QuantoFalta)
before the row applying thereplace
.– BrTkCa
How high is
number
by account, it is necessary to convert tostring
– Pliavi
If Quantofalta is not
string
you can do that:String(QuantoFalta).replace...
– JuniorNunes