用于两像素的WooCommerce转换跟踪脚本
我想通过一些联盟网络推广我的产品 您唯一需要做的就是进入function.php文件并添加带有像素的脚本。使用此脚本,金额值的跟踪工作正常。如果您是唯一的供应商,则此脚本仅适用于一个网络用于两像素的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
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技能有限,因此我想了解如何在不损害(常规)跟踪的情况下修改脚本
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。我会在我的帖子中更新它。我在上面添加了更多问题。