Created
August 7, 2015 17:35
-
-
Save jessehintze/ed8b233fdee17123aef0 to your computer and use it in GitHub Desktop.
Calculates price based off of qty
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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