'There's no shipping tax on woocommerce order dashboard
Solution 1:[1]
Of course it was the code.. I was trying this code that is popular to apply taxes in filter woocommerce_package_rates:
$taxes = array();
// Taxes: Loop through the shipping taxes array (as they can be many)
foreach ($rate->taxes as $key => $tax){
if( $tax > 0 ){
$initial_tax_cost = $tax; // Get the initial tax cost
$tax_rate = $initial_tax_cost / $initial_cost; // Get the tax rate conversion
$taxes[$key] = $new_cost * $tax_rate; // Set the new tax cost in taxes costs array
}
}
$rates[$rate_key]->taxes = $taxes;
Well in my case the $tax was alywas 0. So I discarded the whole thing and had it applying like this:
$rates[$rate_key]->taxes = [$new_cost * $tax_rate];
It worked in checkout but not on order dashboard thus I asked the question.
Changed to this:
$taxes = WC_Tax::calc_shipping_tax( $rate->cost, WC_Tax::get_shipping_tax_rates() );
$rate->set_taxes($taxes);
I don't know why the index must be greater than 0..but well..Everything works now.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | unjoined |

