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

263
Visualizações
Woocommerce review order total hook is echoing result twice

I want to get the cart total figure for which I am using the following code in my functions.php:

function display_total(){
    global $woocommerce;
    $newTotal = $woocommerce->cart->get_total();

    echo $newTotal;
};
add_action( 'woocommerce_review_order_before_order_total', 'display_total');

Instead of displaying the amount once, it does it twice like $18.00$18.00.

Doing a var_dump too results in 2 lines of HTML:

D:\Wordpress\wp-content\themes\new_theme\functions.php:161:string '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">&#36;</span>18.00</bdi></span>' (length=128)

D:\Wordpress\wp-content\themes\new_theme\functions.php:161:string '<span class="woocommerce-Price-amount amount"><bdi><span class="woocommerce-Price-currencySymbol">&#36;</span>18.00</bdi></span>' (length=128)

What am I doing wrong?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Echo the value in a table row, so that it won't echo it twice. So your code would be something like this:

add_action( 'woocommerce_review_order_before_order_total', 'display_total');

function display_total(){
    global $woocommerce;
    $newTotal = $woocommerce->cart->get_total();

    echo '<tr><td >' . $newTotal . '</td></tr>';
};

And the reason is, woocommerce_review_order_after_order_total hook is being used in a table, therefore adding your value between a tr and td tag would result in echoing the value once.

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