Tagged: fees
- This topic has 1 reply, 1 voice, and was last updated 3 weeks, 4 days ago by
Keraton.
-
AuthorPosts
-
March 18, 2025 at 11:19 am #7922
Keraton
ParticipantHello!
I am using the TeraWallet (WooWallet) plugin to enable users to pay for orders from their internal wallet balance. Recently, I encountered an issue related to payments for orders containing additional fees.
My website includes a rental renewal feature that utilizes custom fees: a negative fee (“Previously Paid”) and a positive fee (“Rental Renewal (7 days)”). When selecting payment via TeraWallet, the order successfully updates to the correct status and is extended as intended. However, the amount is not deducted from the user’s internal wallet balance.
Briefly, here’s the logic behind my renewal plugin:
Two fees are added to the order: one negative (the amount previously paid) and one positive (the renewal fee).
The final order amount is the difference between these fees, equal to the rental renewal cost.
The core issue is that TeraWallet doesn’t process these additional fees, consequently failing to deduct the appropriate funds.
Details:
WooCommerce Version: [Your WooCommerce version, e.g., 9.7.1]
TeraWallet Version: [Your TeraWallet version, e.g., 1.5.10]
PHP Version: [Your PHP version, e.g., 8.4]
I would greatly appreciate your assistance in resolving this issue, as it’s an essential functionality for my project.
Thank you in advance!
March 18, 2025 at 11:28 am #7923Keraton
ParticipantI would like to supplement the previously described issue with my perspective on a solution. As a developer, I see a way to resolve the problem as follows:
Solution:
We need to ensure that when calculating the amount to be deducted from the internal wallet, both the product prices and the added fees are taken into account. To achieve this, you can try one of the following approaches:
1. Using a Filter to Recalculate the Order Total
If TeraWallet provides a filter to override the total amount (for example,woo_wallet_order_total
), you can add the following code:php /** * Filter the total amount for wallet deduction, including the fees. */ add_filter( 'woo_wallet_order_total', 'keraton_include_fees_in_wallet_total', 10, 2 ); function keraton_include_fees_in_wallet_total( $total, $order_id ) { $order = wc_get_order( $order_id ); if ( ! $order ) { return $total; } // Calculate the total amount of fees $fees_total = 0; foreach ( $order->get_items( 'fee' ) as $fee_item ) { $fees_total += (float) $fee_item->get_total(); } // Return the adjusted total (products total + fees) return $total + $fees_total; }
2. Adjusting the Balance via a Hook After Successful Payment
If the filter is not available, you can use order status change hooks to manually adjust the user’s balance by deducting the missing amount:php /** * After successful payment, adjust the wallet deduction to include the fee amount, * if the payment method is TeraWallet. */ add_action( 'woocommerce_order_status_pending_to_processing', 'keraton_adjust_wallet_balance_for_fees', 10, 2 ); add_action( 'woocommerce_order_status_pending_to_completed', 'keraton_adjust_wallet_balance_for_fees', 10, 2 ); function keraton_adjust_wallet_balance_for_fees( $order_id, $order ) { if ( 'terawallet' !== $order->get_payment_method() ) { return; } $fees_total = 0; foreach ( $order->get_items( 'fee' ) as $fee_item ) { $fees_total += (float) $fee_item->get_total(); } if ( $fees_total > 0 ) { // It is assumed that the function woo_wallet_subtract_balance exists and handles the wallet deduction. woo_wallet_subtract_balance( $order->get_user_id(), $fees_total, $order_id, 'Adjusting wallet deduction to include fees for order renewal' ); } }
These modifications will ensure that the correct amount, including the fees, is deducted from the user’s internal wallet when renewing an order.
I hope this solution helps to resolve the issue. I look forward to your feedback and further cooperation.
-
AuthorPosts
- You must be logged in to reply to this topic.