I have calculated a different custom order total in Woocommerce:
add_action( 'woocommerce_checkout_create_order', 'change_total_on_checking', 20, 1 );
function change_total_on_checking( $order ) {
// Get order total
$total = $order->get_total();
$orderproduct = $order->get_items();
$tax_rate = WC_Tax::get_rates( $orderproduct );
if ($tax_rate == "10") {
$percent10 = $total * $tax_rate;
}
if ( $tax_rate == "4" ){
$percent4 = $total * $tax_rate;
}
## -- fai check e calcoli -- ##
$new_total = $total + $percent4 + $percent10; // <== Fake calculation
// imposta un calcolo nuovo
$order->set_total( $new_total );
}
But my calculations don't work and I'm not able to make it for instance.
Any advice or help please?
Is there ever a time you would have both tax rates? Otherwise, I would think one variable for taxes would be enough, like so:
if ($tax_rate == "10") {
$tax_total = $total * $tax_rate;
}
if ( $tax_rate == "4" ){
$tax_total = $total * $tax_rate;
}
## -- fai check e calcoli -- ##
$new_total = $total + $tax_total
Also, what do you mean your calculations are working?