Last active
May 29, 2019 10:28
-
-
Save harlantwood/408ea7285ca4b336c75f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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