2017-05-15 13 views
0

일부 제휴사 네트워크를 통해 제품을 홍보하고 싶습니다.두 픽셀에 대한 WooCommerce 전환 추적 스크립트

당신이해야 할 일은 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>'; } 

내 문제

: 나는 제품 배달/구매 처리를 위해 내 플랫폼 이서를 사용하는 여러 공급 업체가 있습니다.

특정 제품을 선택하여 구입 한 경우 두 번째 픽셀에 대해 작동하는 두 번째 스크립트를 추가하기 위해 어떻게 함수 파일을 수정할 수 있는지 알아야합니다.

내 woocommerce 기술이 제한되어 있으므로 (일반적인) 추적을 손상시키지 않으면 서 스크립트를 수정하는 방법을 알고 싶습니다.

  1. "정상적인"제품을 구입 한 사람은 위의 첫 번째 픽셀보다 제품을 발광시켜야합니다.
  2. 누군가 제품 ID 2004로 특정 제품을 구입 한 경우 - 두 번째 다른 픽셀보다 먼저 첫 번째 픽셀을 실행하고 무시해야합니다.

두 번째 기능을 추가하거나 첫 번째 기능을 수정해야합니까?

내가 아마 3 픽셀을 설치해야합니다 당신에게 앞으로

추가 질문 (업데이트 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>'; 
    } 
} 

동일한 구조 변화 아이디 유효도?

제안 내의 제휴 소프트웨어에서 "대상 픽셀" 및 "최종 픽셀"을 사용할 수 있습니다.

일부 제품은 "테스트 제품"이며 값은 0.00입니다. 주 픽셀이 발생하면 고객은 나중에 제품을 구매하더라도 보상을받지 못합니다. 이 경우

대상 화소의 종류는 특정 제품의
변동 ID를 설치해야 할 것이다. 고객이 테스트 월 이후에 구매 결정을 내린 경우 "올바른 픽셀"이 실행되어야합니다.

+0

무엇이'Product_Nr. 2004'는 제품 속성인가? –

+0

답장을 보내 주셔서 감사합니다. 제품 ID 2004는 WooCommerce의 제품 ID 일뿐입니다. 내 게시물에 이것을 업데이 트합니다. – reich

답변

0

주문 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>'; 
    } 
} 

코드 활성 자식 테마 (또는 테마)의 functions.php 파일에 간다 : 여기

는 쿼리를 해결해야하는 샘플 코드입니다. 또는 모든 플러그인 PHP 파일에서.

관련 질문 :이 도움이 How to insert Google Merchant Review JS code in WooCommerce Order Complete page

희망!

+0

놀라운! 이 작품, 고마워요! – reich

+0

위 질문을 추가했습니다. – reich