Send GA4 ecommerce events with functions from Woocommerce – WordPress direct
Purchase event function ga4_purchase_event() { global $wp; if ( is_wc_endpoint_url( ‘order-received’ ) ) { $order_id = $wp->query_vars[‘order-received’]; $order = wc_get_order( $order_id ); $total = $order->get_total(); $currency = get_woocommerce_currency(); echo “<script>gtag(‘event’, ‘purchase’, {‘transaction_id:’$order,’value’:’$total’,’currency’:’$currency’});</script>”; } } add_action( ‘woocommerce_thankyou’, ‘ga4_purchase_event’ ); Add to cart add_action( ‘woocommerce_add_to_cart’, ‘ga4_add_to_cart_event’, 10, 6 ); function ga4_add_to_cart_event( $cart_item_key, $product_id, $quantity, $variation_id, $variation,…