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

105
Visualizações
how can i let google ads conversion tracking read the value of the conversion dynamically?

I am trying to install google ads code to track my conversion for my woocommerce store

this is the code that should be installed in the order confirmation page

<!-- Event snippet for Purchase BSS conversion page -->
<script>
  gtag('event', 'conversion', {
      'send_to': 'AW-608570056/jkryCPDw7_ACEMiVmKIC',
      'value': 0.0,
      'currency': 'USD',
      'transaction_id': ''
  });
</script>

I need the value to be dynamic,

and this is the code I am using in the function.php in order to push this code to the thank you page

<?php
// Add custom Theme Functions here
// 
/**
 * Add custom tracking code to the thank-you page
 */
add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function my_custom_tracking( $order_id ) {

    // Lets grab the order
    $order = wc_get_order( $order_id );

    /**
     * Put your tracking code here
     * You can get the order total etc e.g. $order->get_total();
     */
    
    ?>
    <script>
  fbq('track', 'Purchase');
        
  gtag('event', 'conversion', {
      'send_to': 'AW-608570056/jkryCPDw7_ACEMiVmKIC',
      'value': 0.0,
      'currency': 'USD',
      'transaction_id': ''
  });
</script>

<?php
    // This is the order total
    $order->get_total();
 
    // This is how to grab line items from the order 
    $line_items = $order->get_items();

    // This loops over line items
    foreach ( $line_items as $item ) {
        // This will be a product
        $product = $order->get_product_from_item( $item );
  
        // This is the products SKU
        $sku = $product->get_sku();
        
        // This is the qty purchased
        $qty = $item['qty'];
        
        // Line item total cost including taxes and rounded
        $total = $order->get_line_total( $item, true, true );
        
        // Line item subtotal (before discounts)
        $subtotal = $order->get_line_subtotal( $item, true, true );
    }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You don't need all that code, simply a line that calculates order total, and you can place that directly inside the script. Try with:

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );

function my_custom_tracking( $order_id ) {
    $order = wc_get_order( $order_id );    
    ?>
    <script>
        fbq('track', 'Purchase');   
        gtag('event', 'conversion', {
            'send_to': 'AW-608570056/jkryCPDw7_ACEMiVmKIC',
            'value': <?php echo $order->get_total(); ?>,
            'currency': 'USD',
            'transaction_id': ''
        });
    </script>
    <?php
}
about 4 years ago · Juan Pablo Isaza 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