We are trying to find a way to apply a 20% discount to only certain products if the ss_total_price[i] exceeds $250.
I tried to make this work by creating extra product fields:
Extra Product Field 1: Threshold (250)
Extra Product Field 2: Discount (20)
and the following script placed below the CheckIt function in the shopping cart:
- Code: Select all
<script type="text/javascript">
ss_subtotal = 0;
var discountPercentage = 0;
var discount = 0;
var discountFlag = 0;
for (var i = 0; i < ss_name.length; i++)
{
if (ss_field1[i] != '' && ss_field2[i] != '')
{
if (parseFloat(ss_field1[i]).toFixed(2) <= parseFloat(ss_total_price[i]).toFixed(2))
// if (ss_field1[i] <= ss_total_price[i])
{
discountPercentage = ss_field2[i] / 100;
discount = ss_total_price[i] * discountPercentage;
ss_total_price[i] = ss_total_price[i] - discount;
ss_total_price[i] = Math.round((ss_total_price[i]+ 0.00001) * 100) / 100;
ss_total_price[i] = ss_total_price[i].toFixed(2);
discountFlag = discountFlag + 1;
}
}
ss_subtotal = ss_subtotal + ss_total_price[i];
}
ss_subtotal = parseFloat(ss_subtotal).toFixed(2);
</script>
This appears to work for the first item, but all the other potentially qualifying items get discounted without exceeding the $250 threshold and the ss_subtotal remains stuck at the first ss_total_price[0]. Non-qualifying items appear to be processed correctly, but are not reflected in ss_subtotal.
Can this be done via coupons?
Thanks!