Skip to content

Instantly share code, notes, and snippets.

@webtoffee-git
Created April 28, 2026 04:13
Show Gist options
  • Select an option

  • Save webtoffee-git/ac8e342e1d424824c5f924d493fd622f to your computer and use it in GitHub Desktop.

Select an option

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)
<?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