Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

445
Vistas
Add percentage to the total (including shipping cost) in woocommerce

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, '' );
}
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You can also try this.

add_action( 'woocommerce_cart_calculate_fees','woocommerce_custom_donation',10, 1 );
function woocommerce_custom_donation() {
    global $woocommerce;

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

        $percentage     = 3.5;
        $cart_total     = $woocommerce->cart->cart_contents_total;
        $shipping_total = $woocommerce->cart->get_shipping_total() ?: 0;
        $tax_total      = $woocommerce->cart->get_taxes_total() ?: 0;

        $grand_total = $cart_total + $shipping_total + $tax_total;
        $donation = $grand_total * $percentage / 100;
        $woocommerce->cart->add_fee( 'Administration Fees', $donation, true, '' );
}

enter image description here

over 4 years ago · Santiago Trujillo Denunciar

0

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:

enter image description here

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda