• Resolved WebBuddy

    (@websprout)


    Hi,

    I am placing a pixel tracking code on the order confirmation page and it needs two parameters to be returned. One is the order id and the other is the sales amount. May I know what variable should I use to get these two parameters?

    Thank you in advance!

    https://wordpress.org/plugins/woocommerce/

Viewing 15 replies - 1 through 15 (of 18 total)
  • Try something like this:

    add_action ('woocommerce_thankyou', 'myfunction');
    function myfunction($order_id) {
      $order = new WC_Order($order_id);
      print $order_id.', '.$order->get_total();
    }

    Thread Starter WebBuddy

    (@websprout)

    Hi Iorro,

    Thank you for the help. So does that means I just need to insert the $order_id into the tacking codes? My tacking codes looks like that:

    <iframe src=”http://tracking.shopmarketplacenetwork.com/aff_1?offerid=3&adv_sub=<ORDER_ID>&amount=<SALE_AMT>&#8221; width=”1″ height=”1″/>

    So I can just replace the <ORDER_ID> with $order_id above?

    Yes, but must you will need to use php syntax:

    add_action ('woocommerce_thankyou', 'myfunction');
    function myfunction($order_id) {
      $order = new WC_Order($order_id);
      $sale_amt = $order->get_total();
      print '<iframe src="http://tracking.shopmarketplacenetwork.com/aff_1?offerid=3&adv_sub='.$order_id.'&amount='.$sale_amt.'" width="1" height="1"/>';
    }

    Sorry not tested.

    If you alter anything, validate the changed code with:
    http://phpcodechecker.com/

    Code goes in functions.php for your child theme.

    Thread Starter WebBuddy

    (@websprout)

    Thank you, lorro!

    Does it work for you , Websprout ?

    Where do I need to insert this code , where I also need to conversation tracking
    ” <li class=”total”>
    <?php _e( ‘Total:’, ‘woocommerce’ ); ?>
    <?php echo $order->get_formatted_order_total(); ?>

    <?php if ( $order->payment_method_title ) : ?>
    <li class=”method”>
    <?php _e( ‘Payment Method:’, ‘woocommerce’ ); ?>
    <?php echo $order->payment_method_title; ?>

    <?php endif; ?>

    <div class=”clear”></div>

    <?php endif; ?>

    <?php do_action( ‘woocommerce_thankyou_’ . $order->payment_method, $order->id ); ?>
    <?php do_action( ‘woocommerce_thankyou’, $order->id ); ?>

    <?php else : ?> “”

    Could you please help me Lorro ! , My code is literally same as websprout.
    Thanks in Advance !

    There’s no tracking code in there. The code would just print out the order total and payment method, but not communicate with any tracking service. The code looks rather mixed up.

    Thanks for your quick reply lorro .

    Could please tell me, how could I insert to this code “<iframe src=”http://tracking.shopmarketplacenetwork.com/aff_1?offerid=3&adv_sub=<ORDER_ID>&amount=<SALE_AMT>&#8221; width=”1″ height=”1″/>”
    on a thank you page .

    It is a affiliate tracking code , I want to need conversation tracking after sell .

    Thanks in advance . Any helps will be appropriate

    That looks the same as before. Try the code snippet from my second answer.

    The code goes in functions.php for your theme.

    functions.php will be overwritten every time you update your theme. To get round this problem, make a child theme:
    http://codex.wordpress.org/Child_Themes
    and put the code in functions.php for the child theme.

    If its the first snippet in a php file, it must start with

    <?php

    Hi,
    I’m trying to adapt this code. I added the following to my functions.php in the child theme:

    add_action ('woocommerce_thankyou', 'pix_truck');
    function pix_truck($order_id) {
      $order = new WC_Order($order_id);
      $sale_amt = $order->get_total();
      print '<img src="http://tbs.tradedoubler.com/report?program=275634&event=322134&OrderNumber=$order_id&OrderValue=$sale_amt&Currency=EUR">';
    }

    Is that enough? The tracking code will be inserted in the thank you page, or is there some code I need to insert in thank you page?
    Thanks in advance.

    It looks as if it should work as it is. Run a test order, and when on the thankyou page, look at the page source. In Chrome, use control-u to bring up the source. Look for tradedoubler link, and check its parameter string. You should see that $order_id and $sale_amt have been replaced with the values for your test order.

    Hi Lorro,
    Thanks for your help.
    It looks like there is a problem with my code, since I get a blank page. I guess it is about the ‘ and the “, but I can’t figure it out:

    
    add_action ('woocommerce_thankyou', 'pix_truck');
    function pix_truck($order_id) {
      $order = new WC_Order($order_id);
      $sale_amt = $order->get_total();
      print '<img src="http://tbs.tradedoubler.com/report?program=275634&event=322134&OrderNumber='.$order_id.'&OrderValue='.$sale_amt.'&Currency=EUR">';
    }
    
    
    • This reply was modified 7 years, 6 months ago by pierremaitre.
    
    The ' and " must be the vertical ones, not the slanting ones, but I think yours look like the vertical types so that's OK.
    

    Your code validates here:
    http://phpcodechecker.com/

    So, just asking, does your child theme’s functions.php start with:

    
    <?php
    

    this starts php interpretation of subsequent lines.

    Yes, there are several functions and hooks in it before this one.

    If I replace the URL with:

    
    print '<img src="http://tbs.tradedoubler.com/report?program=275634&event=322134&OrderNumber=$order_id&OrderValue=$sale_amt&Currency=EUR">';
    

    the page displays correctly, but obviously the tracking code is not right. But it seems to me that there is a syntax problem in the url.

    • This reply was modified 7 years, 6 months ago by pierremaitre.

    Did you run the whole file through the validator:
    http://phpcodechecker.com/

    If you still get a white out, take functions.php out of play for a moment by renaming it. If the fault persists it is elsewhere.

Viewing 15 replies - 1 through 15 (of 18 total)
  • The topic ‘How to get woocommerce order id on thank you page’ is closed to new replies.