- type:
- snippet
- category:
- Tax tips and tricks
- name:
- More Tax-inclusive prices, perhaps a better solution.
- versions:
- 060
- reference:
- http://forum.foxycart.com/comments.php?DiscussionID=3547&page=1
- date:
- 2011-05-26
More Tax-inclusive prices, perhaps a better solution.
Put this in the checkout template (right before the closing head tag </head>).
<script type="text/javascript"> function displayCustomTaxes() { var order_total = jQuery("#order_total").val(); //takes the order_total amount (this is now a "string") and puts it in a variable var order_total = order_total.replace(',','.'); //this will replace the "," into "." (this makes the decimals also into the calculation) (example 212,50 into 212.50) var order_total = parseFloat(order_total); //this will take the amount which is a "string", and make it into an "integer" (text into number) var tax = FC.formatter.currency(order_total - (order_total/1.25)); //in Norway our tax is 25%, so this will make the 25% tax calculation jQuery("#tax").val(tax); //this will put the new value into the tax area. } jQuery(document).ready(function () { displayCustomTaxes(); //optional ! this will display the new tax amount BEFORE customers enters in any personal information. FC.checkout.overload("updatePriceDisplay", null, "displayCustomTaxes"); //this will display the new tax amount AFTER customers enters in any personal information }); </script>
Optional! If you also want this in the receipt right after checkout. Put this in the receipt template (right before the closing head tag </head>).
<script type="text/javascript"> $("document").ready(function () { var order_total = $("li.fc_order_total > span.fc_text").html(); //this puts the order_total text-string into an variable var order_total = order_total.replace('kr',''); //this removes the currency format from the string. (Norway uses "kr", but america uses "$". Change "kr" into your countrys currency.) var order_total = order_total.replace(' ',''); //this removes the whitespace in amounts over thousand (12 345,67 into 12345,67) var order_total = order_total.replace(',','.'); //this replaces the "," into "." (for the calculation with decimals) (12345,67 into 12345.67) var order_total = parseFloat(order_total); //this will take the amount which is a "string", and make it into an "integer" (text into number) var tax = order_total - (order_total/1.25); //in Norway our tax is 25%, so this will make the 25% tax calculation var tax = tax.toFixed(2); //this rounds the decimals (up or down) into only two numbers var tax = tax + ''; //this makes the amount back to a "string", so that we can change the "." back to "," var tax = tax.replace('.',','); //changes the "." back to "," $("li.fc_order_tax > span.fc_text").html('kr' + tax); //this puts the new value of tax into the dokument. (Change "kr" into your countrys currency.) }); </script>
This will not change the display of tax on the “email receipt”!