WC_Abstract_Order::apply_coupon_using_edited_totals
Apply a coupon treating manually edited line item totals as the pre-discount price.
When the order has no coupons yet, line items whose total differs from their subtotal adopt that total as the new subtotal, so the discount is calculated from the edited price and recalculations keep the manual adjustment. On failure the original subtotals are restored. Call this only where a subtotal/total difference is meant to be treated as a manual edit, such as the admin order editor; otherwise use apply_coupon().
Метод класса: WC_Abstract_Order{}
Хуков нет.
Возвращает
true|WP_Error. True if applied, error if not.
Использование
$WC_Abstract_Order = new WC_Abstract_Order(); $WC_Abstract_Order->apply_coupon_using_edited_totals( $raw_coupon );
- $raw_coupon(строка|WC_Coupon) (обязательный)
- Coupon code or object.
Список изменений
| С версии 11.2.0 | Введена. |
Код WC_Abstract_Order::apply_coupon_using_edited_totals() WC Abstract Order::apply coupon using edited totals WC 11.3.0
public function apply_coupon_using_edited_totals( $raw_coupon ) {
// With coupons already applied the subtotal/total difference also contains their
// discounts and the manual portion cannot be separated out, so it is left alone.
$original_subtotals = empty( $this->get_items( 'coupon' ) ) ? $this->sync_subtotals_with_manually_edited_totals() : array();
$applied = $this->apply_coupon( $raw_coupon );
if ( is_wp_error( $applied ) ) {
$this->restore_item_subtotals( $original_subtotals );
}
return $applied;
}