Advertisement
Socialking

Untitled

Mar 24th, 2022
878
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.96 KB | None | 0 0
  1. /**
  2.  * This function is called when the customer completes the checkout process.
  3.  * It takes the order ID as an argument and uses it to get the order total.
  4.  * It then uses the order total to send a conversion tracking event to Google Analytics
  5.  *
  6.  * @param order_id The order ID.
  7.  *
  8.  * @return The order total.
  9.  */
  10. add_action('woocommerce_thankyou', 'conversion_tracking_thank_you_page', 95, 1);
  11. function conversion_tracking_thank_you_page($order_id)
  12. {
  13.       $order = wc_get_order($order_id);
  14.  
  15.       if (!$order_id)
  16.             return;
  17.  
  18.       foreach ($order->get_items() as $item_id => $item) {
  19.             $total = $item->get_subtotal_tax();
  20.       }
  21.  
  22.       $product_gtag = '
  23.        <script>
  24.            gtag("event", "page_view", {
  25.                "send_to": "AW-10852304507/GCDUCITa7aMDEPuM5LYo",
  26.                "value": "' .  $total . '",
  27.                "currency": "PLN",
  28.                "transaction_id": ""
  29.            });
  30.        </script>';
  31.       echo $product_gtag;
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement