eMikkelsen
eMikkelsen

Reputation: 411

Global surcharge WooCommerce exclude VAT

I made a global surcharge in PHP for WooCommerce, because all of our customers have to pay a fee for special delivery.

Is there a way to make the fee ignore VAT?

When I write 15 it adds VAT to the number. I'd just like for the number I write to be the fee.

TL:DR - MAKE SURCHARGE INCLUDED VAT

// Packing fee
add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' ); 
function wc_add_surcharge() { 
    global $woocommerce; 

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

    $county = array('DK');
    // change the $fee to set the surcharge to a value to suit
    $fee = 15;

    if ( in_array( WC()->customer->get_shipping_country(), $county ) ) : 
        $woocommerce->cart->add_fee( 'Emballage pant', $fee, true, 'standard' );  
    endif;
}

Upvotes: 0

Views: 92

Answers (1)

LoicTheAztec
LoicTheAztec

Reputation: 253869

To make the fee ignore Vat you need to remove the 2 last arguments as they are related to Taxes (the third argument is false (not taxable) by default ):

Also global $woocommerce; and $woocommerce->cart as there is a missing $cart argument in this hooked function. So try this instead:

// Packing fee
add_action( 'woocommerce_cart_calculate_fees','wc_add_surcharge' ); 
function wc_add_surcharge( $cart ) { 
    if ( is_admin() && ! defined( 'DOING_AJAX' ) ) 
        return;

    $county = array('DK');
    // change the $fee to set the surcharge to a value to suit
    $fee = 15;

    if ( in_array( WC()->customer->get_shipping_country(), $county ) ) : 
        $cart->add_fee( 'Emballage pant', $fee );  
    endif;
}

Code goes in function.php file of your active child theme (or active theme). Tested and work.

Upvotes: 1

Related Questions