In the end I think I found on my own the fix.
Seems fine at first glance.
It will be nice if a developer validates the code and ads the fix in the next official release.
I modified the get earning by order inside dokan-lite/includes/Commision.php
/**
* Get earning by order
*
* @since 2.9.21
* @since 3.7.19 Shipping tax recipient support added.
*
* @param int|WC_Order $order Order.
* @param string $context
*
* @return float|void|WP_Error|null on failure
*/
public function get_earning_by_order( $order, $context = 'seller' ) {
if ( is_numeric( $order ) ) {
$order = wc_get_order( $order );
}
if ( ! $order ) {
return new WP_Error( __( 'Order not found', 'dokan-lite' ), 404 );
}
if ( $order->get_meta( 'has_sub_order' ) ) {
return;
}
// If
_dokan_admin_fee
is found means, the commission has been calculated for this order without the WeDevs\Dokan\Commission
class.
// So we'll return the previously earned commission to keep backward compatability.
$saved_admin_fee = $order->get_meta( '_dokan_admin_fee', true );
if ( $saved_admin_fee !== '' ) {
$saved_fee = ( 'seller' === $context ) ? $order->get_total() - $saved_admin_fee : $saved_admin_fee;
return apply_filters( 'dokan_order_admin_commission', $saved_fee, $order );
}
// Set user passed order_id
$this->set_order_id( $order->get_id() );
// get earning from order table
$earning = $this->get_earning_from_order_table( $order->get_id(), $context );
if ( ! is_null( $earning ) ) {
return $earning;
}
$earning = 0;
$vendor_id = (int) $order->get_meta( '_dokan_vendor_id' );
foreach ( $order->get_items() as $item_id => $item ) {
// Set user passed order_id
so that we can track if any commission_rate has been saved previously.
// Specially on order table re-generation
.
$this->set_order_item_id( $item->get_id() );
// Set line item quantity so that we can use it later in the \WeDevs\Dokan\Commission::prepare_for_calculation()
method
$this->set_order_qunatity( $item->get_quantity() );
$product_id = $item->get_variation_id() ? $item->get_variation_id() : $item->get_product_id();
$refund = $order->get_total_refunded_for_item( $item_id );
if ( dokan_is_admin_coupon_applied( $order, $vendor_id, $product_id ) ) {
$earning += dokan_pro()->coupon->get_earning_by_admin_coupon( $order, $item, $context, $item->get_product(), $vendor_id, $refund );
} else {
$item_price = apply_filters( 'dokan_earning_by_order_item_price', $item->get_total(), $item, $order );
$item_price = $refund ? $item_price - $refund : $item_price;
$item_earning = $this->calculate_commission( $product_id, $item_price, $vendor_id );
$item_earning = 'admin' === $context ? $item_price - $item_earning : $item_earning;
$earning += $item_earning;
}
// reset order item id to zero
$this->set_order_item_id( 0 );
// set order quantity to zero
$this->set_order_qunatity( 0 );
}
// reset order id to zero, we don't need this value anymore
$this->set_order_id( 0 );
if ( $context === $this->get_shipping_fee_recipient( $order ) ) {
$earning += wc_format_decimal( floatval( $order->get_shipping_total() ) ) - $order->get_total_shipping_refunded();
}
if ( $context === $this->get_tax_fee_recipient( $order->get_id() ) ) {
$fees = $order->get_total_fees(); // Get the total fees for the order
$earning += ( ( $order->get_total_tax() - $order->get_total_tax_refunded() ) - ( $order->get_shipping_tax() - $this->get_total_shipping_tax_refunded( $order ) ) ) + $fees;
}
if ( $context === $this->get_shipping_tax_fee_recipient( $order ) ) {
$earning += ( $order->get_shipping_tax() - $this->get_total_shipping_tax_refunded( $order ) );
}
$earning = apply_filters_deprecated( 'dokan_order_admin_commission', [ $earning, $order, $context ], '2.9.21', 'dokan_get_earning_by_order' );
return apply_filters( 'dokan_get_earning_by_order', $earning, $order, $context );
}