skip to Main Content

How could I get order total value of finished woocommerce order into my converse code?

The following code is bellow. I have tried everything and still getting fatal error. The code is located in functions.php in my theme.

add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page' );

function bbloomer_conversion_tracking_thank_you_page() {
?>


<!-- Mìøicí kód Sklik.cz -->
<script type="text/javascript">
var seznam_cId = 100060787;
var seznam_value = null;
</script>
<script type="text/javascript" src="https://www.seznam.cz/rs/static/rc.js" async></script>
<?php
}

I need to modify – > var seznam_value = null; to get the value – price (how much money does the order costs) of finished order to manage conversions on my website.

Thank you for your help!

2

Answers


  1. Chosen as BEST ANSWER

    This did the thing

    <!-- Mìøicí kód Sklik.cz -->
    <script type="text/javascript">
    var seznam_cId = 100060787;
    var seznam_value =<?php echo ($order->get_subtotal()); ?>;
    </script>
    

  2. Trough woocommerce_thankyou() you have access to the $order_id parameter

    $order = wc_get_order( $order_id );

    function action_woocommerce_thankyou( $order_id ) {
        // Get $order object
        $order = wc_get_order( $order_id );
    
        ?>
        <script type="text/javascript">
        var order_total = <?php echo $order->get_total(); ?>;
        console.log( order_total );
        </script>
        <?php
    }
    add_action( 'woocommerce_thankyou', 'action_woocommerce_thankyou', 10, 1 );
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search