Skip to content

Instantly share code, notes, and snippets.

@jessehintze
Created August 7, 2015 17:35
Show Gist options
  • Save jessehintze/ed8b233fdee17123aef0 to your computer and use it in GitHub Desktop.
Save jessehintze/ed8b233fdee17123aef0 to your computer and use it in GitHub Desktop.
Calculates price based off of qty
var originalPrice = $('.regular-price .price').text();
var priceStripped = originalPrice.replace('$', '');
var priceConverted = parseFloat(priceStripped);
var quantity = 1;
//product page qty
$('.sp-input').on('change', function () {
quantity = $(this).val();
var manuStripped = originalPrice.replace('$', '');
var manuConverted = parseFloat(manuStripped);
var manuOriginal = parseFloat(manuStripped);
var priceNew = (manuConverted * quantity).toFixed(2);
if (isNaN(quantity) === true) {
$('.sp-input').val(1);
//$('.regular-price .price').text("$" + manuOriginal);
} else {
$('.regular-price .price').text("$" + priceNew);
}
});
$('.super-attribute-select').on('change', function () {
var priceTotal = $('.regular-price .price').text();
var priceStripped = priceTotal.replace('$', '');
var priceConverted = parseFloat(priceStripped);
var optprice = $('option:selected', this).attr('price');
var priceNew = ((priceConverted + optprice) * quantity).toFixed(2);
$('.regular-price .price').text("$" + priceNew);
});
$('.sp-plus').on('click', function () {
quantity++;
var priceNew = (priceConverted * quantity).toFixed(2);
if (isNaN(quantity) === true) {
$('.sp-input').val(1);
} else {
$('.sp-input').val(quantity);
}
$('.regular-price .price').text("$" + priceNew);
});
$('.sp-minus').on('click', function () {
if (quantity <= 1) {
return false;
} else if (isNaN(quantity) === true) {
$('.sp-input').val(1);
} else {
quantity--;
$('.sp-input').val(quantity);
}
var priceNew = (priceConverted * quantity).toFixed(2);
$('.regular-price .price').text("$" + priceNew);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment