Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

453
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda