Forum Replies Created

Viewing 11 replies - 1 through 11 (of 11 total)
  • Simon Mista

    (@simonmista)

    Hi @19db ,

    Thank you for pointing out the importance of considering multiple VAT rates in the cart. To address this, I’ve updated the code to dynamically calculate a weighted VAT percentage based on the items in the cart. This ensures that the VAT applied to the wallet deduction is accurate even when there are multiple tax rates involved.

    add_action('woocommerce_cart_calculate_fees', function ($cart) {
    if (is_admin() && !defined('DOING_AJAX')) {
    return;
    }

    foreach ($cart->get_fees() as $fee) {
    if (isset($fee->id) && strpos($fee->id, 'wallet') !== false) {
    $original_fee_amount = $fee->amount; // Original net wallet deduction
    $total_vat_percentage = 0;
    $total_cart_net = 0;

    // Calculate weighted VAT percentage based on cart items
    foreach ($cart->get_cart() as $cart_item) {
    $product = $cart_item['data'];
    $tax_class = $product->get_tax_class(); // Product tax class
    $tax_rates = WC_Tax::get_rates($tax_class); // Tax rates based on tax class

    // Get the tax rate
    $tax_rate = !empty($tax_rates) ? array_shift($tax_rates) : null;
    $vat_percentage = isset($tax_rate['rate']) ? floatval($tax_rate['rate']) : 0;

    // Net price of the product item
    $product_price_net = $cart_item['line_total'];
    $total_cart_net += $product_price_net;

    // Add to weighted VAT percentage
    $total_vat_percentage += ($product_price_net / $cart->get_subtotal()) * $vat_percentage;
    }

    // Apply the weighted VAT percentage to the wallet deduction amount
    $fee->amount = $original_fee_amount * (1 + ($total_vat_percentage / 100));
    $fee->total = $fee->amount;

    // Debugging data
    $debug_data = [
    'fee' => [
    'fee_id' => $fee->id,
    'original_amount' => $original_fee_amount,
    'new_amount_with_vat' => $fee->amount,
    ],
    'weighted_vat_percentage' => $total_vat_percentage,
    'total_cart_net' => $total_cart_net,
    ];
    error_log(print_r($debug_data, true)); // Debug log for further analysis
    }
    }
    }, 9999);

    Explanation:

    1. Weighted VAT Percentage: The VAT percentage is calculated dynamically as a weighted average based on the net price of each cart item, ensuring that mixed VAT rates are handled accurately.
    2. Dynamic Wallet Deduction Adjustment: The wallet deduction (fee) is adjusted to include the weighted VAT, ensuring the gross value of the wallet is deducted correctly from the cart total.
    3. Debugging: The code includes an error log (error_log) that records the calculations, including the original fee amount, the weighted VAT percentage, and the final adjusted fee amount, to verify the results.

    Note: This code only works correctly when combined with the following WooCommerce modification:
    /woocommerce/includes/class-wc-cart-totals.php

    $max_discount = round( $this->get_total( 'items_total', true ) + $fee_running_total + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_tax_class_costs() ) ) * -1;

    This approach ensures that the VAT calculations are accurate and consistent for carts with multiple VAT rates.

    @subratamal , could you please contact the WooCommerce support team to address these calculation issues and explain the problem? Additionally, it would be great if you could consider integrating my code into the plugin to ensure accurate VAT calculations.

    Best regards,
    Simon

    Thread Starter Simon Mista

    (@simonmista)

    Yes, thank you.
    this version now seems to work without errors.

    Thread Starter Simon Mista

    (@simonmista)

    Hi @amagsumov
    Take a look at this PHP Notice.
    (there is no stack trace available. Your plugin loads the textdomain to early) – This message was added in version WP Core -> 6.7.0.

    [17-Dec-2024 18:53:23 UTC] PHP Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the cleantalk-spam-protect domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /wp-includes/functions.php on line 6114

    PHP Version: v8.3.14
    WordPress Core: v6.7.0
    CleanTalk: v6.46

    For my setup, it only works correctly if I replace the following line of code:

    $max_discount = round( $this->get_total( 'items_total', true ) + $fee_running_total + $this->get_total( 'shipping_total', true ) + array_sum( $this->get_tax_class_costs() ) ) * -1;
    ------------> includes/class-wc-cart-total.php line no 285

    Additionally, I’ve added the following code to my theme:



    add_action('woocommerce_cart_calculate_fees', function ($cart) {
    foreach ($cart->get_fees() as $fee) {
    if (isset($fee->id) && strpos($fee->id, 'wallet') !== false) {
    $fee->amount = $fee->amount * (1 + 0.19);
    $fee->total = $fee->amount;
    }
    }
    }, 9999);

    Could you please take a look at this? This issue has been around for over 4 years…?https://github.com/woocommerce/woocommerce/issues/28028

    Simon Mista

    (@simonmista)

    I am experiencing a similar issue with the WooWallet plugin. The wallet balance is displayed correctly in the info window, but when applied during checkout, the deducted amount does not match the announced gross value. Instead, the deduction seems to be based on the net value, leading to inconsistencies in the final cart totals.

    For example:

    • Wallet balance:?10 € (Gross)
    • Expected deduction:?-10 €
    • Actual deduction:?-8.40 € (Net)

    This issue becomes even more apparent when the cart total is close to the available wallet balance. The system seems to incorrectly calculate the deduction based on the net value of the wallet, even though the gross value was announced in the info window.

    Can you confirm if the current logic refers to the net value of the cart instead of the gross value during calculation? If so, could the logic be updated to ensure that the gross wallet balance is applied consistently without modifying the cart VAT amount?

    Thank you for your help!

    Best regards,
    Simon

    Forum: Plugins
    In reply to: [WP-SCSS] 3.0 PHP Errors

    This Error is coused by this “Development Settings” -> “Always Recompile”

    u have to disable this option first before update.

    yea …
    Fatal error: Uncaught Error: Class ‘ScssPhp\ScssPhp\Block\MediaBlock’ not found in /xxxxxxxx/plugins/wp-scss/scssphp/src/Parser.php:477

    This Error is coused by this “Development Settings” -> “Always Recompile”

    • This reply was modified 2 years, 4 months ago by Simon Mista.
    Thread Starter Simon Mista

    (@simonmista)

    ok thanks,
    but this solution is not working if you dont have MANUALLY added any page here:
    /wp-admin/admin.php?page=aioseo-sitemaps#/general-sitemap

    is this correct ?

    Thread Starter Simon Mista

    (@simonmista)

    Hi @wpdatatables ,
    yes take a look at this Screenshots:

    For Example 1: WRONG
    (Pages with a Table)
    https://www.crowdfunding.de/magazin/plattform-friedhof/
    IMAGE-> https://www.crowdfunding.de/image_example1_wrong.png

    For Example 2: CORRECT
    (Pages without a Table)
    https://www.crowdfunding.de/magazin/tokenbasierte-crowdinvestments/
    IMAGE-> https://www.crowdfunding.de/image_example2_correct.png

    The Table Plugin adds a “<i>” element with this class: “btn waves-input-wrapper waves-effect” and also the input get a class “waves-button-input”.

    Let me know if you need more informations.

    Thanks

    Hi @tikoqu,
    du musst nur die ?ltere WooCommerce version (3.8.1) installieren dann sollte es wieder funktionieren.
    Du hast sicher die version 3.9.0 installiert oder?

    Hi @aweissinpsyde,
    wisst ihr ungef?hr wann ihr dieses Update ver?ffentlicht?
    Oder vorher vielleicht einen kleinen Patch den man manuell einspielen kann ?

    *kleine info noch:*
    Wenn man bereits eine Bestellung für einen Kunden get?tigt hat und der Kunde dann über eine URL bezahlen will dann wird das Iframe richtig geladen:
    /checkout/order-pay/*/?pay_for_order=true&key=wc_order_*

    Das Iframe funktioniert nur nicht wenn man eine neue Bestellung machen m?chte.

    Viele Grü?e
    Simon

    • This reply was modified 5 years, 1 month ago by Simon Mista.
Viewing 11 replies - 1 through 11 (of 11 total)