1
votes

I'm using the WooCommerce add_fee() to add a packaging fee to my orders.
The Code - in my opinion - is pretty straight forward:

// Add custom cart fee
add_action( 'woocommerce_cart_calculate_fees', 'cp_add_custom_price' );
function cp_add_custom_price( $cart_object ) {
    global $woocommerce;
    $totalGoods = WC()->cart->get_cart_contents_count();

    $feeTitle = ( get_locale() === 'en_US' ) ? 'Package fee' : 'Paketpauschale';
    $fee = 2.48;
    if( $totalGoods > 0 ) {
        $woocommerce->cart->add_fee( $feeTitle, $fee, true );
    }
}

I want the fee to be 2.95€ with german 19% sales tax. In both the cart and during checkout, the Fee is displaying correctly like so:
enter image description here

However after checkout, the fee changes to a much lower number
enter image description here
The left value shows the "total" and the right show's the 19% sales tax.

I have no idea where WooCommerce suddenly gets these values from when I entered 2.48 in my code and when both the cart and checkout pages show the value correctly.
I understand that this might be caused by some other calculations or plugins we are using, but I'm hoping that someone might have ran into the same issue. I am using WooCommerce 3.5.4

Small update: We just got an order from another country with 0% rate. The Price for the fee was correctly calculated at 2.48, so it must be an issue with the 19% sales tax.

1
Are you using WooCommerce Germanized? Because I also had some issues with this kind of code.Mr. Jo

1 Answers

0
votes

On my website the plugin "Germanized for WooCommerce" caused the error. Go to "WooCommerce" > "Einstellungen" > "Germanized" > "Anteilige Steuerberechnung" and disable all settings.