WC_Discounts::apply_coupon_remainder
Deal with remaining fractional discounts by splitting it over items until the amount is expired, discounting 1 cent at a time.
Метод класса: WC_Discounts{}
Хуков нет.
Возвращает
int. Total discounted.
Использование
// protected - в коде основоного (родительского) или дочернего класса $result = $this->apply_coupon_remainder( $coupon, $items_to_apply, $amount );
- $coupon(WC_Coupon) (обязательный)
- Coupon object if applicable. Passed through filters.
- $items_to_apply(массив) (обязательный)
- Array of items to apply the coupon to.
- $amount(int) (обязательный)
- Fixed discount amount to apply.
Список изменений
| С версии 3.2.0 | Введена. |
Код WC_Discounts::apply_coupon_remainder() WC Discounts::apply coupon remainder WC 10.8.1
protected function apply_coupon_remainder( $coupon, $items_to_apply, $amount ) {
$total_discount = 0;
foreach ( $items_to_apply as $item ) {
$quantity = NumberUtil::ceil( $item->quantity );
for ( $i = 0; $i < $quantity; $i++ ) {
// Find out how much price is available to discount for the item.
$price_to_discount = $this->get_discounted_price_in_cents( $item );
// Run coupon calculations.
$discount = min( $price_to_discount, 1 );
// Store totals.
$total_discount += $discount;
// Store code and discount amount per item.
$this->discounts[ $coupon->get_code() ][ $item->key ] += $discount;
if ( $total_discount >= $amount ) {
break 2;
}
}
if ( $total_discount >= $amount ) {
break;
}
}
return $total_discount;
}