Created
April 28, 2026 04:13
-
-
Save webtoffee-git/ac8e342e1d424824c5f924d493fd622f to your computer and use it in GitHub Desktop.
Code snippet to recalculate the order totals automatically during import - by Webtoffee (Order Import Export for WooCommerce)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php // Do not copy this line of code | |
| /** | |
| * Re-enable WooCommerce order total recalculation during WT Import Export order import. | |
| * | |
| * This ensures WooCommerce rebuilds the internal tax and totals structure | |
| * for imported orders so that third-party invoice and reporting plugins | |
| * display the correct tax labels and subtotal values. | |
| * | |
| * @param WC_Order $order The order object being prepared for insertion. | |
| * @param array $data Raw import data. | |
| * | |
| * @return WC_Order | |
| */ | |
| add_filter( | |
| 'wt_woocommerce_import_pre_insert_order_object', | |
| 'wt_recalculate_order_totals_during_import', | |
| 10, | |
| 2 | |
| ); | |
| function wt_recalculate_order_totals_during_import( $order, $data ) { | |
| if ( ! $order instanceof WC_Order ) { | |
| return $order; | |
| } | |
| $order->calculate_totals(); | |
| return $order; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment