Skip to content

Instantly share code, notes, and snippets.

@mikejolley
Last active April 23, 2018 13:31
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mikejolley/1847058 to your computer and use it in GitHub Desktop.
Save mikejolley/1847058 to your computer and use it in GitHub Desktop.
WooCommerce - Custom tracking code
add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
function my_custom_tracking( $order_id ) {
// Lets grab the order
$order = wc_get_order( $order_id );
/**
* Put your tracking code here
* You can get the order total etc e.g. $order->get_total();
*/
// This is the order total
$order->get_total();
// This is how to grab line items from the order
$line_items = $order->get_items();
// This loops over line items
foreach ( $line_items as $item ) {
// This will be a product
$product = $order->get_product_from_item( $item );
// This is the products SKU
$sku = $product->get_sku();
// This is the qty purchased
$qty = $item['qty'];
// Line item total cost including taxes and rounded
$total = $order->get_line_total( $item, true, true );
// Line item subtotal (before discounts)
$subtotal = $order->get_line_subtotal( $item, true, true );
}
}
@Firestorm-Graphics
Copy link

is this delivery tracking or analytics ?

@chirag-v
Copy link

What's the alternative for WooCommerce 2.1?

@Spreeuw
Copy link

Spreeuw commented Mar 1, 2016

$order->get_order_total() is deprecated since version 2.1 and replaced by $order->get_total()

@nichetom
Copy link

Hi Mike, I appreciate that.

Could you please walk me through how I could update this iframe code?

I will send you $35 paypal for your time if possible.

`<!-- BEGIN COMMISSION JUNCTION TRACKING CODE -->

<iframe height="1" width="1" frameborder="0" scrolling="no" src="https://www.emjcd.com/tags/c?containerTagId=14209&ITEMx=$product->get_sku();&AMTx=[AmountofItem]&QTYx=[Quantity]&CID=1529328&OID=[OID]&TYPE=385769&AMOUNT=[Subtotal]&DISCOUNT=[DiscountAmount]&CURRENCY=[CURRENCY]&COUPON=[couponcode]" name="cj_conversion" ></iframe>

<!-- END COMMISSION JUNCTION TRACKING CODE -->`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment