0

I can't add the HT in my cart. I have to have the TTC and HT displayed here. enter image description here The TTC is 22,80 €. And the HT, it is 19 €. The VAT is 3,80€.

I have this code


// For Woocommerce 2.5+ (2.6.x and 3.0)

add_action('woocommerce_cart_calculate_fees', 'prefix_add_tva_line', 10, 1);
function prefix_add_tva_line($cart)
{
// is_admin Détermine si la demande actuelle concerne une page
//d'interface administrative.

    if (is_admin() && !defined('DOING_AJAX')) {
        return;
    }

    $discount = 0;
    // Get the unformated taxes array.
    // Obtenez le tableau des taxes non formées.
    // $cart->get_taxes(); il y a deux tableaux array(1){[1]=>float(3.8)} array(1){[1]=>float(3.8)}.
    $taxes = $cart->get_taxes();

    // Ajouter chaque taxe à $discount.
    // $taxes c'est le tableaux a parcourir et $taxe c'est la valeur taxe est assignée
    foreach ($taxes as $tax) {
        $discount = $tax;
    }
    // Applying a discount if not null or equal to zero.
    // applique a discount si elle n'est pas nulle ou égale à zéro.
    if ($discount > 0 && !empty($discount)) {
        $cart->add_fee(__('TVA', 'HT'), + $discount);
    }
}

which gives me 3,80€ in Tax, but that in positive (+), that makes 22,80€ + 3.80€ = 26,60€.

enter image description here

Even if I do $cart->add_fee(__('VAT', 'HT'), **-** $discount); the calculation of the VAT will still be done.

maka
  • 39
  • 7
  • add_fee have 4 parameters WC_Cart::add_fee( $name, $amount, $taxable, $tax_class );. Try add_fee( __('VAT', 'HT'), -$discount, false, '' ); – Snuffy Feb 02 '23 at 09:06
  • Sorry, @Martin Mirchev, the WC_Cart::add_fee( $name, $amount, $taxable, $tax_class ); where do I put it? – maka Feb 02 '23 at 09:32

0 Answers0