I'm creating Woocommerce totals 'on-the-fly' as my cart items are imported from another CMS.
Currently I am having trouble setting a custom 'fee' for each order, then marking the order as 'on-hold':
$order->set_date_created($creation_tsz);
$order->set_address( $address, 'billing' );
$order->set_address( $address, 'shipping' );
$order->set_currency('GBP');
$order->add_fee('Imported Total', $imported_total_here);
$order->set_fee();
$order->calculate_totals();
$order->update_status('on-hold');
Any track on this will be appreciated.
To add a Fee to an order programmatically since Woocommerce 3, it's a bit more complicated. There are some parameters to set as the Fee name, the tax status, the tax class (if needed) and the fee amount (excl. taxes).
Also to make the tax calculations, depending on the taxes settings, you will need to set an array containing at minima the customer country code (if the taxes are based on the country)
Let say that the fee amount variable name is
$imported_total_fee
in the code below:Tested and perfectly works.