• Resolved Daniel

    (@kngqe)


    Starting with Dokan Lite 3.8 the order fees are missing from the vendor earnings.

    They were present before the update.

    The order fees are supported by Dokan Lite and have a dedicated file: dokan-lite/templates/orders/order-fee-html.php

    To make the issue clearer, this is a potential solution to show the vendor earnings together with the order fees.

    <?php
        $earning = dokan()->commission->get_earning_by_order( $order );
        $total_fees = $order->get_total_fees();
        $earning_with_fees = $earning + $total_fees;
        echo wp_kses_post( wc_price( $earning_with_fees ) );
    ?>
    • This topic was modified 1 year, 6 months ago by Daniel.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Daniel

    (@kngqe)

    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 );
    }
    
    Plugin Support Tanvir Hasan

    (@tanvirh)

    Hi @kngqe

    Glad to know that you have found the solutions on your own and we really appreciate that!

    Regarding adding the solutions to the Dokan Lite near future release. We encourage you to submit an enhancement request to our development team through the following link:

    https://github.com/weDevsOfficial/dokan/issues/new/choose

    By doing so, you can directly contribute to the improvement of our plugin, and our development team will carefully consider your suggestion for future updates.

    I hope this help.

    Thanks!

    Thread Starter Daniel

    (@kngqe)

    Hi @tanvirh ,

    My issue is solved.

    A Dokan developer provided me the complete solution on GitHub.

    Thank you!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Dokan Lite 3.8 / Order fees are missing from vendor earnings’ is closed to new replies.