-1

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!

Saigonns
  • 35
  • 10
  • Does this answer your question? [How to get WooCommerce order details](https://stackoverflow.com/questions/39401393/how-to-get-woocommerce-order-details) – 7uc1f3r Apr 08 '20 at 13:46
  • It would be great if you could tell me what code to input insted of null vallue because I have tried almost everything and still got an error – Saigonns Apr 08 '20 at 13:47

2 Answers2

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 );
7uc1f3r
  • 28,449
  • 17
  • 32
  • 50
  • Great code, it could help but It did not help in this case, I have post the answer to the topic. Thank you for your help anyway. :) – Saigonns Apr 08 '20 at 14:30
0

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>
Saigonns
  • 35
  • 10