title: WooCommerce Conversion Tracking Script for two Pixel
body: <p>I want to promote my products by some affiliate networks.</p>
  
  <p>Do only thing you have to do, is to go into the function.php file and add this script with the pixel. With this script the tracking of the amount value works fine. This script works <strong>only for one network</strong> and if you are the only vendor.</p>
  
  <pre><code>add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
  function my_custom_tracking( $order_id ) {
    $order = new WC_Order( $order_id );
    $total = $order-&gt;get_subtotal();
    $id = str_replace('#', '', $order-&gt;get_order_number());
    echo '&lt;iframe src="https://network.com/track?offer_id=666&amp;amount=' . $total . '&amp;track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"&gt;&lt;/iframe&gt;';
  }
  </code></pre>
  
  <p><strong>My problem:</strong> I have multiple Vendors who are using my plattform for Product delivery / purchase processing.</p>
  
  <p>I need to know how i can modify the function file in order to add a working second script for a 2nd pixel if a specific product has been selected and bought.</p>
  
  <p>My it skills in woocommerce are limited, so i would like to understand how to modify the script without harming the (general) tracking.</p>
  
  <ol>
  <li>If somebody buys the "normal" Products than the 1st pixel above should fire.</li>
  <li>If somebody buys a specific product with the Product ID 2004 - than a 2nd different pixels needs to fire and ignore the first pixel.</li>
  </ol>
  
  <p>Do i need to add a second function or modify the first one?</p>
  
  <p>Thank you</p>
  
  <p><strong>Additional questions (Update 16.05.2017)</strong></p>
  
  <p>In the future I will probably have to install a third pixel. How would the structure be?</p>
  
  <pre><code>add_action('woocommerce_thankyou', 'wh_custom_tracking');
  
  function wh_custom_tracking($order_id)
  {
      $product_ids = [2004, 2000]; //&lt;-- list of product_id(s) for which 2nd pixels should fire
      $checkSecond = FALSE;
      $product_ids = [2003, 2001]; //&lt;-- list of product_id(s) for which 3nd pixels should fire
   $checkThird = FALSE;
      $order = wc_get_order($order_id);
      $total = $order-&gt;get_subtotal();
      $id = str_replace('#', '', $order-&gt;get_order_number());
  
      $items = $order-&gt;get_items();
  
      foreach ($items as $item)
      {
          $item_id = $item['product_id']; // &lt;= 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 '&lt;iframe src="https://network.com/track?offer_id=666&amp;amount=' . $total . '&amp;track_id=' . $id . '" scrolling="no" frameborder="0" width="1" height="1"&gt;&lt;/iframe&gt;';
      }
  }
  </code></pre>
  
  <p>Is the same structure also valid for <strong>variation IDs</strong>?</p>
  
  <p>In the affiliate software within the offer a <strong>"Target pixel"</strong> and the "final pixel" can be used.</p>
  
  <p>Some products are "test products" and have a value of € 0.00. If the main pixel fires, then the affiliate receives no compensation, even if the customer afterwards purchases the product.</p>
  
  <p>In this case, a kind of <strong>target pixel</strong> would have to be installed for the <strong>variation ID of a particular product</strong>. If the customer decides after the test month for the purchase, then the "right pixel" should fire.</p>