WC_Abstract_Order::restore_item_subtotals
Restore item subtotals changed by sync_subtotals_with_manually_edited_totals(), so that a failed coupon application leaves the in-memory order unchanged.
Method of the class: WC_Abstract_Order{}
No Hooks.
Returns
void. Nothing (null).
Usage
// private - for code of main (parent) class only $result = $this->restore_item_subtotals( $original_subtotals );
- $original_subtotals(array) (required)
- Original tax and subtotal values, keyed by item ID.
WC_Abstract_Order::restore_item_subtotals() WC Abstract Order::restore item subtotals code WC 11.2.1
private function restore_item_subtotals( array $original_subtotals ) {
foreach ( $original_subtotals as $item_id => $original ) {
$item = $this->get_item( $item_id, false );
if ( ! $item instanceof WC_Order_Item_Product ) {
continue;
}
// Restoring the per-rate taxes recomputes both tax totals, so it runs before the
// stored totals are put back.
if ( ! empty( $original['taxes']['total'] ) ) {
$item->set_taxes( $original['taxes'] );
}
$item->set_subtotal( $original['subtotal'] );
$item->set_subtotal_tax( $original['subtotal_tax'] );
$item->set_total_tax( $original['total_tax'] );
}
}