To get the tax rate(s) from an order you will have to get order "tax" item(s).
You will get WC_Order_Item_Tax
protected Object(s) and you have to use the dedicated available methods.
Sample code:
// Get an instance of the WC_Order Object
$order = wc_get_order($order_id);
// Loop through order tax items
foreach( $order->get_items('tax') as $item ){
$name = $item->get_name(); // Get rate code name (item title)
$rate_code = $item->get_rate_code(); // Get rate code
$rate_label = $item->get_label(); // Get label
$rate_id = $item->get_rate_id(); // Get rate Id
$tax_total = $item->get_tax_total(); // Get tax total amount (for this rate)
$ship_total = $item->get_shipping_tax_total(); // Get shipping tax total amount (for this rate)
$is_compound = $item->is_compound(); // check if is compound (conditional)
$compound = $item->get_compound(); // Get compound
}
Note: An order can have multiple tax rates (items "tax").
You can also use some related WC_Abstract_Order
methods on the WC_Order
Object to get:
- Get the tax location for the order:
$order->get_tax_location()
(array).
- Get all tax classes for items in the order:
$order->get_items_tax_classes()
(array). It will display an empty value for the "Standard" tax class.