Skip to content

Instantly share code, notes, and snippets.

@juanlistab
Last active October 31, 2023 00:36
Show Gist options
  • Select an option

  • Save juanlistab/981a73269cda33339a99028159220a19 to your computer and use it in GitHub Desktop.

Select an option

Save juanlistab/981a73269cda33339a99028159220a19 to your computer and use it in GitHub Desktop.
Calculate totals based on product price #wpai #hpos #wpallimport

Calculate order totals based on product price in WP All Import

Instructions:

  • Use this code in your Function Editor and leave the Totals field empty.

Disclaimer:

  • This will work with your import using the current tax rates, it won't work for any past rates.
  • Keep in mind that this is an example function, and you may need to modify it to work on your site.
function my_recalc_order( $post_id, $xml_node, $is_update ) {

    // Retrieve the import ID.
    $import_id = wp_all_import_get_import_id(); 

    // Change '1' to your import ID.
    if ( $import_id == '1' ) {
        $order = new \WC_Order( $post_id );
        $order->calculate_totals( );
    }
}
add_action( 'pmxi_saved_post', 'my_recalc_order', 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment