• Resolved mina404

    (@mina404)


    Hi,

    I have a question about how tax is calculated in relation to coupon discounts and wallet payments on an order.

    Currently, the calculation order seems to be:
    (Item price − Discount) × 1.10 (tax) − Wallet amount

    What I need instead is:
    (Item price − Discount − Wallet amount) × 1.10 (tax)

    In other words, I want the discount and the wallet amount to both be subtracted from the item price before the 10% tax is applied, rather than having the wallet amount subtracted after tax is calculated.

    I noticed there’s a setting called “Tax Calculation Mode” with two options:

    1. “Wallet pays for goods only; tax is calculated on the order”
    2. “Wallet pays for the entire order including tax”

    Does switching between these two options change the order of operations (i.e., whether the wallet amount is deducted before or after tax is calculated), or does it only affect how the wallet-paid portion is recorded for tax/accounting purposes?

    If this setting does not control the calculation order I described above, is there a filter/hook (or any supported way) to make the wallet amount get subtracted together with the discount before tax is calculated, instead of after?

    Thank you for your help.

Viewing 1 replies (of 1 total)
  • Plugin Author Subrata Mal

    (@subratamal)

    Yes, this is definitely achievable with some custom code. You can implement the attached code by adding it to your active theme’s functions.php file.

    /**
    * Use TeraWallet's taxable-fee branch, which lets WooCommerce apportion the
    * negative fee's tax across the cart's tax classes instead of stripping it.
    */
    add_filter( 'woo_wallet_partial_payment_tax_mode', static function () {
    return 'tax_inclusive_wallet';
    }, 99 );

    /**
    * Stop that branch grossing the fee base down by the tax rate. With rate 0 the
    * fee base is the entered wallet amount, so WooCommerce's negative fee tax
    * shrinks the taxable base by exactly that amount. Also caps the applied amount
    * at the cart's ex-tax total, which is WooCommerce's own negative-fee ceiling.
    */
    add_filter( 'woo_wallet_partial_payment_effective_tax_rate', '__return_zero', 99 );

    /**
    * Debit only the fee base, not base + its negative tax.
    *
    * Core's get_order_partial_payment_amount() returns abs( total + total_tax ),
    * which here would over-debit by the tax the wallet is not paying.
    *
    * @param float $amount Amount core derived.
    * @param int $order_id Order ID.
    * @return float
    */
    add_filter( 'woo_wallet_order_partial_payment_amount', static function ( $amount, $order_id ) {
    if ( ! function_exists( 'is_partial_payment_order_item' ) ) {
    return $amount;
    }

    $order = wc_get_order( $order_id );
    if ( ! $order ) {
    return $amount;
    }

    $total = 0.0;
    foreach ( $order->get_items( 'fee' ) as $item_id => $item ) {
    if ( is_partial_payment_order_item( $item_id, $item ) ) {
    $total += (float) $item->get_total( 'edit' );
    }
    }

    return abs( $total );
    }, 99, 2 );
Viewing 1 replies (of 1 total)

You must be logged in to reply to this topic.