skip to Main Content

I am trying to get a value of order by PHP (in thank you page) and then use it in script as attribute (attribute v= in src link).

This is for Woocommerce

add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page' );

function bbloomer_conversion_tracking_thank_you_page() {
?>
    <!-- Měřicí kód Sklik.cz -->
<iframe width="119" height="22" frameborder="0" scrolling="no" src="//c.imedia.cz/checkConversion?c=100056379&amp;color=ffffff&amp;v="></iframe>
<?php
}

I hoped that this code will work, but it doesnt.

    add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page' );

    function bbloomer_conversion_tracking_thank_you_page() {
    $price=$order->get_total();
?>
        <!-- Měřicí kód Sklik.cz -->
    <iframe width="119" height="22" frameborder="0" scrolling="no" src="//c.imedia.cz/checkConversion?c=100056379&amp;color=ffffff&amp;v=$price"></iframe>
    <?php
    }

2

Answers


  1. https://developer.wordpress.org/reference/functions/add_action/

    add_action('woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page');
    
    function bbloomer_conversion_tracking_thank_you_page()
    {
        echo '<!-- Měřicí kód Sklik.cz -->
        <iframe width="119" height="22" frameborder="0" scrolling="no" src="//c.imedia.cz/checkConversion?c=100056379&amp;color=ffffff&amp;v="></iframe>';
    }
    
    
    Login or Signup to reply.
  2. Can you add more details, like the order number variable and where you want to insert.
    A.S. as you add these details i will edit the answer or/and add a new answer.

    Edit:
    You can’t write php variables in a non-php script.
    If you want to add a link, i suggest sing echo like this: this is your fixed code:

        add_action( 'woocommerce_thankyou', 'bbloomer_conversion_tracking_thank_you_page' );
    
        function bbloomer_conversion_tracking_thank_you_page() {
        $price=$order->get_total();
    ?>
            <!-- Měřicí kód Sklik.cz -->
        <iframe width="119" height="22" frameborder="0" scrolling="no" src="//c.imedia.cz/checkConversion?c=100056379&amp;color=ffffff&amp;v=<?php echo $price ?>"></iframe>
        <?php
        }
    

    Enjoy your day!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search