在 Woocommerce 中使用交易 ID 嵌入 clickwork7 跟踪代码 [英] Embed clickwork7 tracking code with the transaction ID in Woocommerce

查看:102
本文介绍了在 Woocommerce 中使用交易 ID 嵌入 clickwork7 跟踪代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Woocommerce 中,我希望在创建订单时在付款前获取订单 ID.我在下面找到了这个答案:
之前在结帐页面获取订单ID付款流程

In Woocommerce, I was looking to get order ID just before payment, when the order is created. I found this answer below:
Get the order ID in checkout page before payment process

我需要的是在跟踪脚本中传递交易 ID(在脚本中指定),我应该能够在 clickwork7 仪表板:

What I need is to pass in tracking script the transaction ID (as specified on the script) and I should be able to track in clickwork7 dashboard:

<script type="text/javascript" src="https://clickwork7secure.com/p.ashx?
o=45875&e=12995&f=js&t=TRANSACTION_ID"></script>

但是例如在 Paypal 中购买后交易 ID 似乎是空的,所以我可能应该改为传递订单 ID.

But the transaction ID seems to be empty after a purchase in Paypal for example, so may be I should pass the order ID instead.

Order received 页面似乎是正确的位置,但是对于取消或失败的订单,在哪里以及如何嵌入此脚本?

The Order received page seems to be the right place, but for cancelled or failed orders, Where and how to embed this script?

感谢任何帮助.

推荐答案

更新:可以为此使用许多不同的钩子:

Updated: It is possible to use many different hooks for that:

  • wp_head
  • wp_footer
  • woocommerce_thankyou

您可以尝试使用:

  • 订单编号(很容易拿到)
  • 订单键:$order_key = get_post_meta( $order_id, '_order_key', true );
  • 交易id:$transaction_id = get_post_meta( $order_id, '_transaction_id', true );

1) 使用 woocommerce_thankyou 钩子:更简单的方法因为订单 ID 是一个钩子参数:

1) Using woocommerce_thankyou hook: The simpler way as the Order Id is a hook argument:

add_action( 'woocommerce_thankyou', 'checkout_clickwork_js_script', 22, 1 );
function checkout_clickwork_js_script( $order_id ) {
    if (  ! $order_id  ) return; // Exit

    $transaction_id = get_post_meta( $order_id, '_transaction_id', true );
    $order_key      = get_post_meta( $order_id, '_order_key', true );

    if( ! empty($transaction_id) ){
        $value = $transaction_id; // TRANSACTION ID
    }
    elseif( ! empty($order_key) ){
        $value = $transaction_id; // ORDER KEY
    } 
    else { 
        $value = $transaction_id; // ORDER ID

    $url = "https://clickwork7secure.com/p.ashx?o=45875&e=12995&f=js&t=$value";

    ?><script type="text/javascript" src="<?php echo $url; ?>"></script> <?php
}

代码位于活动子主题(或活动主题)的 function.php 文件中.它应该可以工作.

Code goes in function.php file of your active child theme (or active theme). It should work.

2) 使用 wp_head 钩子:

add_action( 'wp_head', 'checkout_clickwork_js_script', 998 );
function checkout_clickwork_js_script() {
    // Only order-received page 
    if( is_wc_endpoint_url('order-received') ) :

    global $wp;

    $order_id  = absint( $wp->query_vars['order-received'] );

    if ( ! $order_id || empty($order_id) )
        return; // Exit

    $transaction_id = get_post_meta( $order_id, '_transaction_id', true );
    $order_key      = get_post_meta( $order_id, '_order_key', true );

    if( ! empty($transaction_id) ){
        $value = $transaction_id; // TRANSACTION ID
    }
    elseif( ! empty($order_key) ){
        $value = $transaction_id; // ORDER KEY
    } 
    else { 
        $value = $transaction_id; // ORDER ID

    $url = "https://clickwork7secure.com/p.ashx?o=45875&e=12995&f=js&t=$value";

    ?><script type="text/javascript" src="<?php echo $url; ?>"></script> <?php
    endif;
}

代码位于活动子主题(或活动主题)的 function.php 文件中.它应该可以工作.

Code goes in function.php file of your active child theme (or active theme). It should work.

条件 if( is_wc_endpoint_url('order-received') ) : 也可以扩展到处理取消和失败的订单自定义端点……

The condition if( is_wc_endpoint_url('order-received') ) : can be extended to handle cancelled and failed orders custom endpoints too …

<小时>

类似的答案:


Similar answers:

这篇关于在 Woocommerce 中使用交易 ID 嵌入 clickwork7 跟踪代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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