Skip to content

Instantly share code, notes, and snippets.

@tankbar
Last active December 6, 2017 14:16
Show Gist options
  • Save tankbar/bab0629a6f4820ee52a7b66ca3cc15ac to your computer and use it in GitHub Desktop.
Save tankbar/bab0629a6f4820ee52a7b66ca3cc15ac to your computer and use it in GitHub Desktop.
ImBox Chat tracking on Thank you page
<?php
// ImBox Thank you page - Sales Confirmation page
add_action( 'woocommerce_thankyou', 'imbox_tracking_cart', 80 );
function imbox_tracking_cart( $order_id ) {
$order = new WC_Order( $order_id );
$order_nr = $order->get_order_number();
$order_email = get_user_meta( $order->user_id, 'billing_email', true );
$order_quantity = $order->get_item_count();
$order_total_shipping = $order->get_total_shipping();
$order_total_ex_vat = $order->get_total() - $order->get_total_tax();
$order_total = $order_total_ex_vat - $order_total_shipping;
$order_total_inc_vat = $order->get_total() - $order_total_shipping;
?>
<?php
$line_items = $order->get_items();
$product_list = '';
// This loops over line items
foreach ( $line_items as $item ) {
$product_name = $item["name"];
}
$product_list = implode( ',', $product_name );
?>
<!-- ImBox tracking conversation script -->
<script type="text/javascript">
var deviceType = /iPad/.test(navigator.userAgent) ? "t" : /Mobile|iP(hone|od)|Android|BlackBerry|IEMobile|Silk/.test(navigator.userAgent) ? "m" : "d";
var _imbox = _imbox || [];
_imbox.push(['insertTrans', '<?php echo $order_nr; ?>', '', '<?php echo $order_total_inc_vat; ?>', '<?php echo $product_list; ?>',
'<?php echo $order->get_total_tax(); ?>', '<?php echo $order_total_shipping; ?>', 'deviceType']);
</script>
<?php
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment