WC_Abstract_Order::set_item_discount_amounts
After applying coupons via the WC_Discounts class, update line items.
Метод класса: WC_Abstract_Order{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->set_item_discount_amounts( $discounts );
- $discounts(WC_Discounts) (обязательный)
- Discounts class.
Список изменений
| С версии 3.2.0 | Введена. |
Код WC_Abstract_Order::set_item_discount_amounts() WC Abstract Order::set item discount amounts WC 10.4.0
protected function set_item_discount_amounts( $discounts ) {
$item_discounts = $discounts->get_discounts_by_item();
$tax_location = $this->get_tax_location();
$tax_location = array( $tax_location['country'], $tax_location['state'], $tax_location['postcode'], $tax_location['city'] );
if ( $item_discounts ) {
foreach ( $item_discounts as $item_id => $amount ) {
$item = $this->get_item( $item_id, false );
// If the prices include tax, discounts should be taken off the tax inclusive prices like in the cart.
if ( $this->get_prices_include_tax() && wc_tax_enabled() && ProductTaxStatus::TAXABLE === $item->get_tax_status() ) {
$taxes = WC_Tax::calc_tax( $amount, $this->get_tax_rates( $item->get_tax_class(), $tax_location ), true );
// Use unrounded taxes so totals will be re-calculated accurately, like in cart.
$amount = $amount - array_sum( $taxes );
}
$item->set_total( max( 0, $item->get_total() - $amount ) );
}
}
}