Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save harlantwood/408ea7285ca4b336c75f to your computer and use it in GitHub Desktop.
Save harlantwood/408ea7285ca4b336c75f to your computer and use it in GitHub Desktop.
<?php
function order_items_include_tracking_pixel($order) {
foreach ( $order->get_items() as $item ) {
$product = $order->get_product_from_item( $item );
if ( ! $product ) { continue; }
$sku = $product->get_sku();
if (preg_match('/-tp$/', $sku) === 1) {
return true;
}
}
return false;
}
function my_custom_tracking( $order_id ) {
$order = new WC_Order( $order_id );
if (order_items_include_tracking_pixel($order)) {
$total = $order->get_order_total();
// DO YOUR CUSTOM BEHAVIOR HERE
}
}
add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment