I am trying to modify order line sub/totals after order submit using the hook 'woocommerce_checkout_create_order_line_item'
. I can change the values, and they show up correctly in the order email, but the order total doesn’t update.
add_action('woocommerce_checkout_create_order_line_item', 'css_modify_order', 10, 4);
function css_modify_order($item, $cart_item_key, $values, $order) {
$item->set_subtotal(50);
$item->set_total(50);
}
I thought, since this is modifying the order item before it is added to the order, that WooCommerce would get the correct total amount further along in its code execution, before the order is saved.
I have tried using $item->save();
and $item->apply_changes()
, but there was no change in the order total. $order->save_items()
throws an error, and $order->save()
has no effect.
I must be missing something. How do you modify an order item and have the order total come out correctly?