WooCommerceThankyou 跟踪代码安装位置 [英] WooCommerce Thankyou tracking code installation placement

查看:44
本文介绍了WooCommerceThankyou 跟踪代码安装位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Wordpress 开发的新手,正在尝试在 thankyou.php 页面上安装流量垃圾跟踪代码.

到目前为止我的尝试失败了,我认为归结为对 PHP 的理解不够好.

来自trafficjunky 的两个可用跟踪代码是HTML 或PHP

HTML:

<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&IDACTIONC;ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0"/>

PHP:

 <img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=<?=$randomNumber ?><e$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0"/>

我尝试在 thankyou.php WooCommerce 模板上的一些 PHP 代码下进行订单处理后安装 HTML 版本:

**<p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( '谢谢.您的订单已收到.','woocommerce' ), $order );?></p><ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details"><li class="woocommerce-order-overview__order order"><?php _e( '订单号:', 'woocommerce');?><strong><?php echo $order->get_order_number();?></strong><li class="woocommerce-order-overview__date date"><?php _e( '日期:', 'woocommerce');?><strong><?php echo wc_format_datetime( $order->get_date_created() );?></strong><?php if ( is_user_logged_in() &&$order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?><li class="woocommerce-order-overview__email email"><?php _e( 'Email:', 'woocommerce');?><strong><?php echo $order->get_billing_email();?></strong><?php endif;?><li class="woocommerce-order-overview__total total"><?php _e( 'Total:', 'woocommerce');?><strong><?php echo $order->get_formatted_order_total();?></strong><?php if ( $order->get_payment_method_title() ) : ?><li class="woocommerce-order-overview__payment-method method"><?php _e('付款方式:', 'woocommerce');?><strong><?php echo wp_kses_post( $order->get_payment_method_title() );?></strong><?php endif;?><img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSIDACTION]&cti=[TRANSIDACTION]&cti=[TRANSIDACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0"/><?php endif;?><?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id());?><?php do_action('woocommerce_thankyou', $order->get_id());?><?php 其他:?><p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( '谢谢.您的订单已收到.','woocommerce' ), null );?></p><?php endif;?>

**

这导致了订单错误,所以我想弄清楚如何安全地添加跟踪代码的 PHP 版本而不会引发错误.

任何帮助将不胜感激.

感谢您的回复,我已按照说明在functions.php 中设置了该函数,但仍然无法触发跟踪代码.这是我当前的代码:

add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );函数 tracking_code_thankyou($order_id){$random_number = time() .mt_rand(1000, 9999999);$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);?><em>您的跟踪代码就在下面(用于测试)</em><img id="1000145711_cpa_testing" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=<?=$&=$>>$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0"/><?php

}}

解决方案

UPDATED

不是覆盖 thankyou.php 模板,因为你可以看到它的源代码有这一行:

<?php do_action('woocommerce_thankyou', $order->get_id());?>

这意味着您可以使用带有自定义函数的这个 woocommerce_thankyou 动作挂钩来输出此模板行中的任何内容.首先清除模板中的代码...

我还更正了图片链接中的代码,因为它不正确.您应该在活动子主题或活动主题的 function.php 文件中使用以下代码:

add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );函数 tracking_code_thankyou( $order_id ) {$random_number = time() .mt_rand(1000, 9999999);$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);$ URL =https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=$randomNumber&epu=$currentPage&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]";echo '<em>您的跟踪代码就在下面(用于测试)</em><img id="1000143661_tester" src="'.$url.'" width="1" height="1" border="0"/>';}

它会在收到订单页面末尾的客户详细信息之后输出您的代码......

I am new to Wordpress development and am trying to install a traffic junky tracking code on the thankyou.php page.

My attempt has failed so far and I think it boils down to not understanding PHP well enough.

The two tracking codes from trafficjunky that were available were HTML or PHP

HTML:

<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />

PHP:

 <?php
    $randomNumber = time() . mt_rand(1000, 9999999);
    $currentPage = substr($_SERVER["REQUEST_URI"], 0, 255);
?>
<img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=<?=$randomNumber ?>&epu=<?=$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />

I tried to install the HTML version after the order processes under some PHP code on the thankyou.php WooCommerce template:

**<?php else : ?>

            <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), $order ); ?></p>

            <ul class="woocommerce-order-overview woocommerce-thankyou-order-details order_details">

                <li class="woocommerce-order-overview__order order">
                    <?php _e( 'Order number:', 'woocommerce' ); ?>
                    <strong><?php echo $order->get_order_number(); ?></strong>
                </li>

                <li class="woocommerce-order-overview__date date">
                    <?php _e( 'Date:', 'woocommerce' ); ?>
                    <strong><?php echo wc_format_datetime( $order->get_date_created() ); ?></strong>
                </li>

                <?php if ( is_user_logged_in() && $order->get_user_id() === get_current_user_id() && $order->get_billing_email() ) : ?>
                    <li class="woocommerce-order-overview__email email">
                        <?php _e( 'Email:', 'woocommerce' ); ?>
                        <strong><?php echo $order->get_billing_email(); ?></strong>
                    </li>
                <?php endif; ?>

                <li class="woocommerce-order-overview__total total">
                    <?php _e( 'Total:', 'woocommerce' ); ?>
                    <strong><?php echo $order->get_formatted_order_total(); ?></strong>
                </li>

                <?php if ( $order->get_payment_method_title() ) : ?>
                    <li class="woocommerce-order-overview__payment-method method">
                        <?php _e( 'Payment method:', 'woocommerce' ); ?>
                        <strong><?php echo wp_kses_post( $order->get_payment_method_title() ); ?></strong>
                    </li>
                <?php endif; ?>

            </ul>
            <img id="1000143661_tester" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000143661&member_id=1000734841&cb=[RANDOM_NUMBER]&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
        <?php endif; ?>

        <?php do_action( 'woocommerce_thankyou_' . $order->get_payment_method(), $order->get_id() ); ?>
        <?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>

    <?php else : ?>

        <p class="woocommerce-notice woocommerce-notice--success woocommerce-thankyou-order-received"><?php echo apply_filters( 'woocommerce_thankyou_order_received_text', __( 'Thank you. Your order has been received.', 'woocommerce' ), null ); ?></p>

    <?php endif; ?>

</div>**

This led to order errors so i am trying to figure out how to add the PHP version of the tracking code safely without throwing errors.

Any help would be appreciated.

Thank you for the replies, I have set up the function in functions.php as instructed but I am still having trouble getting the tracking code to fire. Here is my current code:

add_action( 'woocommerce_thankyou', 'tracking_code_thankyou', 10, 1 );

function tracking_code_thankyou($order_id){

$random_number = time() . mt_rand(1000, 9999999);
$current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
?>
<em>Your tracking code just below (for testing)</em>
<img id="1000145711_cpa_testing" src="https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=<?=$randomNumber ?>&epu=<?=$currentPage ?>&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]" width="1" height="1" border="0" />
<?php

} }

解决方案

UPDATED

Instead of overriding the thankyou.php template as you can see its source code there is this line:

<?php do_action( 'woocommerce_thankyou', $order->get_id() ); ?>

Which means that you can use this woocommerce_thankyou action hook with a custom function, to output anything in this template line. First get the template clean of your code...

Also I have corrected your code in the image link, as it was not correct. You should use the following code in the function.php file of your active child theme or active theme:

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

    $random_number = time() . mt_rand(1000, 9999999);
    $current_page = substr($_SERVER["REQUEST_URI"], 0, 255);
    $url = "https://ads.trafficjunky.net/tj_ads_pt?a=1000145711&member_id=1000785411&cb=$randomNumber&epu=$currentPage&cti=[TRANSACTION_UNIQ_ID]&ctv=[VALUE_OF_THE_TRANSACTION]&ctd=[TRANSACTION_DESCRIPTION]";

    echo '<em>Your tracking code just below (for testing)</em>
    <img id="1000143661_tester" src="'.$url.'" width="1" height="1" border="0" />';
}

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

这篇关于WooCommerceThankyou 跟踪代码安装位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆