Reputation: 1171
Hi currently i want to get the name of the tax rate in woocommerce. I there any way to get the value that is circled in this picture: https://i.sstatic.net/pyGAH.png
My current code:
$items = $order->get_items();
$lineItem = array();
$productInfo = $orderInfo = array();
$order_items = array();
if ($items) foreach ($items as $item_key => $item_value) {
$_tax = new WC_Tax();
$_product = $order->get_product_from_item( $item_value );
$product_tax_class = $_product->get_tax_class();
$tax_class = $item_value['tax_class'];
Upvotes: 2
Views: 2933
Reputation: 27599
You would use the WC_Tax()->find_rates()
method. It takes an array as an argument, which in your case would be array( 'country' => 'NO' )
and returns an array of matching tax rates. One of the keys of this array is label
which contains the name of the tax rate.
$tax = new WC_Tax();
$country_code = 'NO'; // or populate from order to get applicable rates
$rates = $tax->find_rates( array( 'country' => $country_code ) );
foreach( $rates as $rate ){
$tax_rate_name = $rate['label'];
}
To find the applicable tax rates for a specific order, populate the array for find_rates()
with values from the shipping/billing address on the order.
Upvotes: 5