WC_Shipping_Method::get_taxes_per_item PHP Method

get_taxes_per_item() protected method

Calc taxes per item being shipping in costs array.
Since: 2.6.0
protected get_taxes_per_item ( array $costs ) : array
$costs array
return array of taxes
    protected function get_taxes_per_item($costs)
    {
        $taxes = array();
        // If we have an array of costs we can look up each items tax class and add tax accordingly
        if (is_array($costs)) {
            $cart = WC()->cart->get_cart();
            foreach ($costs as $cost_key => $amount) {
                if (!isset($cart[$cost_key])) {
                    continue;
                }
                $item_taxes = WC_Tax::calc_shipping_tax($amount, WC_Tax::get_shipping_tax_rates($cart[$cost_key]['data']->get_tax_class()));
                // Sum the item taxes
                foreach (array_keys($taxes + $item_taxes) as $key) {
                    $taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
                }
            }
            // Add any cost for the order - order costs are in the key 'order'
            if (isset($costs['order'])) {
                $item_taxes = WC_Tax::calc_shipping_tax($costs['order'], WC_Tax::get_shipping_tax_rates());
                // Sum the item taxes
                foreach (array_keys($taxes + $item_taxes) as $key) {
                    $taxes[$key] = (isset($item_taxes[$key]) ? $item_taxes[$key] : 0) + (isset($taxes[$key]) ? $taxes[$key] : 0);
                }
            }
        }
        return $taxes;
    }