Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用于两像素的WooCommerce转换跟踪脚本_Woocommerce_Tracking_Hook Woocommerce_Affiliate - Fatal编程技术网

用于两像素的WooCommerce转换跟踪脚本

用于两像素的WooCommerce转换跟踪脚本,woocommerce,tracking,hook-woocommerce,affiliate,Woocommerce,Tracking,Hook Woocommerce,Affiliate,我想通过一些联盟网络推广我的产品 您唯一需要做的就是进入function.php文件并添加带有像素的脚本。使用此脚本,金额值的跟踪工作正常。如果您是唯一的供应商,则此脚本仅适用于一个网络 add_action( 'woocommerce_thankyou', 'my_custom_tracking' ); function my_custom_tracking( $order_id ) { $order = new WC_Order( $order_id ); $total = $ord

我想通过一些联盟网络推广我的产品

您唯一需要做的就是进入function.php文件并添加带有像素的脚本。使用此脚本,金额值的跟踪工作正常。如果您是唯一的供应商,则此脚本仅适用于一个网络

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://network.com/track?offer_id=666&amount=' . $total . '&track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
}
add_action('woocommerce_thankyou'、'my_custom_tracking');
功能my\u custom\u tracking($order\u id){
$order=新WC\U订单($order\U id);
$total=$order->get_subtotal();
$id=str#replace('#','$order->get_order_number());
回声';
}
我的问题:我有多个供应商正在使用我的平台进行产品交付/采购处理

我需要知道如何修改功能文件,以便在选择和购买特定产品时为第二个像素添加第二个工作脚本

我在woocommerce的it技能有限,因此我想了解如何在不损害(常规)跟踪的情况下修改脚本

  • 如果有人购买了“普通”产品,则上面的第一个像素应该会触发
  • 如果有人购买了产品ID为2004的特定产品,则需要激发第二个不同像素并忽略第一个像素
  • 我需要添加第二个函数还是修改第一个函数

    多谢各位

    其他问题(2017年5月16日更新)

    在未来,我可能需要安装第三个像素。结构会是怎样的

    add_action('woocommerce_thankyou', 'wh_custom_tracking');
    
    function wh_custom_tracking($order_id)
    {
        $product_ids = [2004, 2000]; //<-- list of product_id(s) for which 2nd pixels should fire
        $checkSecond = FALSE;
        $product_ids = [2003, 2001]; //<-- list of product_id(s) for which 3nd pixels should fire
     $checkThird = FALSE;
        $order = wc_get_order($order_id);
        $total = $order->get_subtotal();
        $id = str_replace('#', '', $order->get_order_number());
    
        $items = $order->get_items();
    
        foreach ($items as $item)
        {
            $item_id = $item['product_id']; // <= Here is your product ID
            if (in_array($item_id, $product_ids))
    
            {
                $checkSecond = TRUE;
                break;
            }
    
     {
                $checkThird = TRUE;
                break;
            }
        }
    
        if ($checkSecond)
        {
            //add your 2nd pixel here 2nd pixel
        }
        else
    
        if ($checkThird)
        {
            //add your 3nd pixel here 2nd pixel
        }
        else
        {
            echo '<iframe src="https://network.com/track?offer_id=666&amount=' . $total . '&track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
        }
    }
    
    add_action('woocommerce_thankyou','wh_custom_tracking');
    自定义跟踪功能($order\u id)
    {
    $product_ids=[2004,2000];//获取订单号();
    $items=$order->get_items();
    foreach($items作为$item)
    {
    
    $item_id=$item['product_id'];//您可以按订单id获取产品id列表,然后您可以应用调节并触发不同的像素

    下面是一个示例代码,可以解决您的查询:

    add_action('woocommerce_thankyou', 'wh_custom_tracking');
    
    function wh_custom_tracking($order_id)
    {
        $product_ids = [2004, 2000]; //<-- list of product_id(s) for which 2nd pixels should fire
        $checkSecond = FALSE;
        $order = wc_get_order($order_id);
        $total = $order->get_subtotal();
        $id = str_replace('#', '', $order->get_order_number());
    
        $items = $order->get_items();
    
        foreach ($items as $item)
        {
            $item_id = $item['product_id']; // <= Here is your product ID
            if (in_array($item_id, $product_ids))
            {
                $checkSecond = TRUE;
                break;
            }
        }
    
        if ($checkSecond)
        {
            //add your 2nd pixel here 2nd pixel
        }
        else
        {
            echo '<iframe src="https://network.com/track?offer_id=666&amount=' . $total . '&track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"></iframe>';
        }
    }
    
    add_action('woocommerce_thankyou','wh_custom_tracking');
    自定义跟踪功能($order\u id)
    {
    $product_ids=[2004,2000];//获取小计();
    $id=str#replace('#','$order->get_order_number());
    $items=$order->get_items();
    foreach($items作为$item)
    {
    
    $item_id=$item['product_id'];//什么是
    product_Nr.2004
    是产品属性还是什么?谢谢你的回复。product id 2004只是WooCommerce中的产品id。我会在我的帖子中更新它。我在上面添加了更多问题。