Advertisement
Imperative-Ideas

eBay Tracking Code for WooCommerce 2.x

Oct 22nd, 2013
1,827
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.22 KB | None | 0 0
  1. <?php
  2.     /**
  3.      * eBay Pixel Tracking Code for WooCommerce
  4.      * @author : eBay / PeppermintJamNetwork
  5.      * @author : Imperative Ideas (@imperativeideas)
  6.      * @description : A modified version of the eBay Tracking Code for use with WooCommerce 2.x
  7.      */
  8.    
  9.     // Enter your product ID below (IMPORTANT)
  10.     $pid = "";
  11.  
  12.     /** DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU ARE DOING **/
  13.  
  14.     $order_id = $_GET['order'];
  15.     $order = new WC_Order($order_id);
  16.     $items = $order->get_items();
  17.  
  18.     //order discount total
  19.     $discount = $order->get_order_discount();
  20.  
  21.         //Begin the output, replace iframe with <pre> in order to see result w/o sending
  22.         $output = '<iframe src="https://t.pepperjamnetwork.com/track?';
  23.         $output .= "PID=$pid"; // gets the product ID variable
  24.         $output .= "&INT=ITEMIZED"; // This is so eBay understands the formatting
  25.  
  26.         $i = 1; //Start the counter and iterate per product in the loop
  27.         foreach( $items as $item ) {
  28.             if ( $item['product_id'] > 0 ) {    // We should replace this with !empty()
  29.                 $quantity = $item['qty'];       // Get data from the order
  30.                 $price = $item['line_total'];       // Get data from the order
  31.  
  32.                     if ( !empty($item['variation_id']) ) {      // Check for a product variation
  33.                             $id = $item['variation_id'];        // Assign variation ID
  34.                     } else {
  35.                     $id = $item['product_id'];      // Else use base ID
  36.                     }
  37.  
  38.                     // Get the SKU based on the product ID (order does not tell us this information)
  39.                     $productmeta = new WC_Product($id);
  40.                     $sku = $productmeta->post->sku;
  41.  
  42.             //add_qty($quantity);
  43.             $output .= '&ITEM' . $i . '=' . $sku;   // write SKU to output
  44.             $output .='&QTY'.$i.'='. $quantity; // write quantity to output
  45.  
  46.             if ($i == 1 && $discount) {     // Check for a coupon & calculate
  47.                 $returnprice = $price - $discount;
  48.                 $output .='&TOTALAMOUNT'.$i.'='. $returnprice;
  49.             } else {
  50.                 $output .='&TOTALAMOUNT'.$i.'='. $price;
  51.             }
  52.  
  53.             $i++; //increase the counter
  54.             }
  55.         }
  56.  
  57.         $output .='&OID='.$order_id;                    // Output order ID
  58.     $output .='" width="1" height="1" frameborder="0"></iframe>';   // Close iframe (or <pre> if echoing)
  59.     echo $output;                           // Echo result
  60.     ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement