Home > Software engineering >  How to use WooCommerce product base price with jQuery | Gravity Form
How to use WooCommerce product base price with jQuery | Gravity Form

Time:09-28

Why doesn't the below work, and how should I do this? Do you have a better and shorter way to write this code?

I also viewed this page but did not notice: enter link description here

$(function() {

var FinalPrice;
var BasePrice = $('.woocommerce-variation-price .amount').text();
// I think the problem is here


$('.Select_plooi input[type="radio"]').on('change',function(){  
var plooi=$('input[name="input_4"]:checked').val();

switch (plooi)
{
    case 'Enkele':
        FinalPrice=BasePrice*2;
        break;
    case 'Dubble':
        FinalPrice=BasePrice*5;
        break;
    case 'Wave':
        FinalPrice=BasePrice*6;
        break;
        }
    });
    
$("#input_2_9").val(parseFloat(FinalPrice).toFixed(2));
});

CodePudding user response:

$('.woocommerce-variation-price .amount') will return price with currency symbol html element is not Int try this:

var BasePrice = parseFloat($('.woocommerce-variation-price .amount').text().replace(/[^\d.,]/g, '')); // remove all non numeric
  • Related