Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. <?php add_action( 'woocommerce_thankyou', 'my_custom_tracking' );
  2.  
  3. function my_custom_tracking( $order_id ) {
  4. // Lets grab the order
  5. $order = wc_get_order( $order_id );
  6.  
  7. //Everflow order objects
  8. $efOrder = array();
  9. $efOrder['items'] = array();
  10. $efOrder['oid'] = $order_id;
  11. $efOrder['amt'] = $order->get_total();
  12. $efOrder['bs'] = $order->get_billing_state();
  13. $efOrder['bc'] = $order->get_billing_country();
  14.  
  15. // Determine if any coupons were used for this transaction
  16. $coupons = '';
  17. if( $order->get_used_coupons() ) {
  18. foreach( $order->get_used_coupons() as $coupon) {
  19. $coupons .= $coupon.',';
  20. }
  21. }
  22. $efOrder['cc'] = $coupons;
  23.  
  24. // This is how to grab line items from the order
  25. $line_items = $order->get_items();
  26.  
  27. // This loops over line items
  28. $efItems = array();
  29. foreach ( $line_items as $item ) {
  30. //Init Everflow item
  31. $efItem = array();
  32. // This will be a product
  33. $product = $order->get_product_from_item( $item );
  34. // This is the products SKU (variant or parent)
  35. $efItem['vs'] = '';
  36. $efItem['ps'] = '';
  37. if ( $product->get_type() === 'variation' )
  38. { $efItem['vs'] = $product->get_sku(); }
  39. else
  40. { $efItem['ps'] = $product->get_sku(); }
  41. // This is the qty purchased
  42. $efItem['qty'] = $item['qty'];
  43. // Line item total cost including taxes and rounded
  44. $efItem['p'] = $order->get_line_total( $item, true, true );
  45. // Add this to Everflow items
  46. $efItems[] = $efItem;
  47. }
  48. $efOrder['items'] = $efItems;
  49.  
  50. $javascriptCode = '
  51. <script type="text/javascript"
  52. src="https://https://soulcbd.endtrk.com/scripts/sdk/everflow.js"></script>
  53.  
  54. <script type="text/javascript">
  55. EF.conversion({
  56. offer_id: 1,
  57. amount: '.$order->get_total().',
  58. order: '.json_encode($efOrder).',
  59. coupon_code: '.$order->get_used_coupons().',
  60. });
  61. </script>';
  62. echo $javascriptCode;
  63. }
  64. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement