1

I'm using Woocommerce, it's up to date.

I've been looking for answers about my issue. I found quite a lot of posts about it but they don't seem to help me figure out the solution.

Found this website that describes how to hook the conversion code.

I tried quite a lot of snippets but the code doesn't fire.

Basically, I've got an iframe code that I need to add to my conversion page. This page is created from the template <b>thankyou.php</b>

I added some code through a hook to function.php but the iframe doesn't show up in the conversion page.

In order to test the code, I've been checking the network tab in "inspect element". It doesn't fire, I cannot even find the code in the page.

Here's the iframe code:

[iframe src="https://lb.affilae.com/?key=59f3463ce8faceb82f8b4571-
59f345fedca96b441b37b6ce&id={UNIQUE_ID}&amount={AMOUNT}&payment=
{PAYMENT}&cv={CUSTOM_VAR}" frameborder="0" width="1" height="1"]

It is a wordpress shortcode, the only way for it to show up on the page.

Here's the hook I've been using:

add_action( 'woocommerce_thankyou', 'bbloomer_add_content_thankyou' );

function bbloomer_add_content_thankyou() {
echo 'my iframe conversion code';
}

Do you have any idea how to fix this? I can provide more info if needed.

Edit:

I found a solution!

The main issue came from the fact that I didn't specified the unique ID and the amount.

Here's the code that solved it all:

add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
function my_custom_tracking( $order_id ) {   
$order = new WC_Order( $order_id );   
$total = $order->get_subtotal();   
$id = str_replace('#', '', $order->get_order_number());   
echo '<iframe src="https://lb.affilae.com/?[replace with the right code]&id=' . $id . '&amount=' . $total . 
'&payment=online&cv={CUSTOM_VAR}" frameborder="0" width="1" height="1">
</iframe>'; 
}

I pasted this code at the top of the function.php file (after

JAGENI Nat
  • 69
  • 8
  • check [this answer](https://stackoverflow.com/a/43303436/5019802) and also [this one](https://stackoverflow.com/a/46886893/5019802). _Hope this helps!_ – Raunak Gupta Dec 06 '17 at 14:20

1 Answers1

2

Updated - You should try this:

add_action( 'woocommerce_thankyou', 'add_custom_content_to_thankyou', 10, 1 );
function add_custom_content_to_thankyou( $order_id ) {

    // The dynamic link in your iFrame
    $src = "https://lb.affilae.com/?key=59f3463ce8faceb82f8b4571-
59f345fedca96b441b37b6ce&id={UNIQUE_ID}&amount={AMOUNT}&payment=
{PAYMENT}&cv={CUSTOM_VAR}"

    echo '<p>Tracking code:<p>'; // Just for testing

    echo do_shortcode("[iframe src=$src]");

}

Code goes in function.php file of your active child theme (or active theme) or in any plugin file.

It will output your code just after customers details at the end of the order-received page…

Related: WooCommerce Thankyou tracking code installation placement

LoicTheAztec
  • 229,944
  • 23
  • 356
  • 399
  • Hi Loic, Thanks for you answer! I tried it but it seems like my website doesn't like the iframe code. When I paste the code to any .php file, my website crashes. I tried removing some lines and it seems that it only crashes when there is the iframe code. Do you have idea how to fix this issue? I'm looking for answers in other threads. Also, the text in

    didn't show up on the page.
    – JAGENI Nat Dec 07 '17 at 09:27
  • 1
    @JAGENINat It means that there is a problem with your theme or something else like a plugin… – LoicTheAztec Dec 07 '17 at 11:26