Reputation: 2968
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$242
on 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.
Upvotes: 2
Views: 1824
Reputation: 253859
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.
Upvotes: 2