In Woocommerce I would like to add 3.5% on the Grand Total (including shipping fee). For now im using these code, but this only calculate without shipping fee.
add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_donation' );
function woocommerce_custom_donation() {
global $woocommerce;
if ( is_admin() && ! defined( 'DOING_AJAX' ) )
return;
$percentage = 0.035; // 3.5%
// uncomment the line below to include shipping fees in the donation/surcharge calculation
// $donation = ( $woocommerce->cart->cart_contents_total + $woocommerce->cart->shipping_total ) * $percentage;
$donation = $woocommerce->cart->cart_contents_total * $percentage;
$woocommerce->cart->add_fee( 'Administration Fees', $donation, true, '' );
}
2
Answers
I believe that when the product is in the cart, the delivery method (and related fees) are not known/applied until checkout.
So I would add a "checkout fee" on checkout, and so after the user selected a checkout method (and why not a payment method)
If you enable tax calculation in Woocommerce settings, you could also set up a tax for everyone that also applies on shipping fees:
You can also try this.