I am building my website by using woocommerce, but i faced the problem of calculating the total amount of the order.
There is a shipping method which is 15% additional fee of the order, and there is a coupon offers $10 discount.
But woocommerce seems like apply the coupon before calculate shipping fee.
For example, the order total amount is $100, the expected result should be (100*1.15) - 10 = 105, but when i tested in the checkout page, the total amount is (100-10) * 1.15 = 103.5.
May I know how to apply the coupon after calculate the shipping fee?
Thank you.
I want to calculate amount correctly in woocommerce, which is apply coupon after calculate the shipping fee.
In Woocommerce I am using Woocommerce One Page Checkout plugin and I would like to add 10% GST on the Grand Total.
Here is an example (without 10% GST on the Grand Total):
Cart Total: $200
Delivery charges: $20
Grand Total: $220
The result should look (with 10% GST on the Grand Total):
Cart Total: $200
Delivery charges: $20
Grand Total: $242 (including 10% of cart total + 10% on Delivery)
On Products listing page, here is what I did to show total like I want:
$woocommerce->cart->total = $woocommerce->cart->total + number_format(($woocommerce->cart->total * 10) /100, 2);
The problem is that when I place an order, I have a grand total of $220 instead of $242on the payment page.
How can I update the order total here?
Is there any way that we can a 10% GST on the total cart amount in Woocommerce?
Note: I tried to debug it using Network calls and found that Woocommerce is sending cart array that includes all the products with a total and order page might be calculating the total again excluding GST I applied using above code block.
The following code will add 10% to the grand total:
add_filter( 'woocommerce_calculated_total', 'custom_cart_grand_total', 20, 2 );
function custom_cart_grand_total( $total, $cart ) {
return $total * 1.10;
}
Code goes in function.php file of your active child theme (or active theme). Tested and works.
I would like to display on the product page and cart the price of the product with 4 decimals (example: 3.2534). But I need to keep the currency settings with 2 decimals for total calculations of the shopping cart (example: 10 units x 3.2534 = 32.53). How can I do this without affecting the final calculation?
In WooCommerce I can only enter the shipping price excluding tax.
How can I make the given price including tax?
The settings to show 'prices including tax' only applies to the products.
So for example if I enter in the settings shipping €1,00
It shows on the checkout €1,21 (0,21 = tax)
It should be €1,00 (incl. 0,21 tax)
(Don't care about the calculation here, it's just an example)
Thanks if anybody has a solution or function for this.
A year after the original question I just hit the same problem and there is not a lot out there to help.
On investigation this turns out to be a problem with the shipping tax calculation from "class-wc-tax.php" which as you can see below hard codes shipping to be tax exclusive.
/**
* Calculate the shipping tax using a passed array of rates.
*
* #param float Price
* #param array Taxation Rate
* #return array
*/
public static function calc_shipping_tax( $price, $rates ) {
$taxes = self::calc_exclusive_tax( $price, $rates );
return apply_filters( 'woocommerce_calc_shipping_tax', $taxes, $price, $rates );
}
It turns out that for some reason that woo have pushed this assumption of shipping being tax exclusive through their down stream tax calculations so you will need to add a couple of filters to your functions.php in order to fix things.
1) The first to calculate the inclusive tax
function yourname_fix_shipping_tax( $taxes, $price, $rates) {
if(wc_prices_include_tax()){
return WC_Tax::calc_inclusive_tax( $price, $rates );
}
return $taxes;
}
add_filter( 'woocommerce_calc_shipping_tax', 'yourname_fix_shipping_tax',10,3);
Careful that you don't forget the 10,3 at the end of add_filter. The 10 is the priority which I have left at the default. The 3 is the number of arguments. You really need this one - the filter displays behavioral problems if you leave it out.
2) The second filter is to fix the totals in downstream calculations.
function yourname_fix_totals( $cart) {
if(wc_prices_include_tax()){
$cart->shipping_total -= $cart->shipping_tax_total;
}
}
add_filter( 'woocommerce_calculate_totals', 'yourname_fix_totals');
Detail for those that worry that this is real money and real taxes we are talking about
The first filter is fairly straight forward - it simply recalculates the tax in the inclusive case.
The second filter is to deal with woo pushing the assumption of exclusive tax further into their tax calculations.
Around line 1396 of 'class-wc-cart.php' we have the following.
// Grand Total - Discounted product prices, discounted tax, shipping cost + tax
$this->total = max( 0, apply_filters( 'woocommerce_calculated_total', round( $this->cart_contents_total + $this->tax_total + $this->shipping_tax_total + $this->shipping_total + $this->fee_total, $this->dp ), $this ) );
What this wants to do is add the shipping tax to the shipping total which we don't want it to do - and they have hard coded it in......
What we will do is use the conveniently located 'woocommerce_calculate_totals' filter() a few lines above around line 1392 to subtract the shipping tax from the total before it all gets added up using the second filter above.
// Allow plugins to hook and alter totals before final total is calculated
do_action( 'woocommerce_calculate_totals', $this );
In an earlier cut of this post from a few weeks back I was worried that this would be a can of worms - and it is turning out to be just that now that I can test things.
So huge caveat here. Test your final tax totals and subtotals thoroughly - this is no longer possibly a risk. Woo have made the assumption of tax exclusive shipping and have pushed it through their downstream calculations. Unfortunately you will have to pay tax to your respective governments even if there was a bug in you code.
Remember also when testing that when you change from exclusive to inclusive taxes in woocommerce settings that old prices are not affected, so you may need to use clean test data.
With all that said so far it is looking ok for me, but in my scenario I am bypassing large amounts of woo - I am not using any of their front end code which means I may not have found other places impacted by the assumption of tax exclusive shipping.
A possible alternative solution is to manually adjust the pricing for shipping so it becomes VAT exclusive. I.e. if shipping incl 20% tax is 6 EUR, adjust it to 5 EUR. Note that this only works if your tax rate is the same for all shipping destinations.
I'm having a strange issue on Magento Grand Total.
I have a product of 99.99€ (inc. tax). The tax is 23% rate.
I have created a Promo Code to have 25% discount on that product.
I've set up the Tax Calculation Method based on the Row Total
I've set up the Apply Customer Tax to be after discount
I've set up the Apply Discount on Prices to be including tax.
The problem comes when I add the product and put a promo code, that created a change on 0.01€. Changing the precision to 4 or the rounding to 4 sometimes solves the issue but creates issues with payment gateways.
The cart page shows the following info:
Subtotal Excl Tax - 81.29
Subtotal Incl Tax - 99.99
Discount - 25.00
Tax - 14.02
Grand Total - 74.98
The grand total should be 74.99€ (99.99€ from the product - 25.00€ from the discount).