WC_Shipping_Method::get_taxes_per_item()
Calc taxes per item being shipping in costs array.
Метод класса: WC_Shipping_Method{}
Хуков нет.
Возвращает
Массив
. of taxes
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->get_taxes_per_item( $costs );
- $costs(массив) (обязательный)
- Costs.
Список изменений
С версии 2.6.0 | Введена. |
Код WC_Shipping_Method::get_taxes_per_item() WC Shipping Method::get taxes per item WC 9.7.1
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; }