Skip to content

Commit 2d60468

Browse files
authored
Merge pull request #3292 from woocommerce/fix/GOOWOO-503-purchase-events-variation-id
Use variations IDs in conversion events
2 parents 740136e + ad740c4 commit 2d60468

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/Google/GlobalSiteTag.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public function maybe_display_conversion_and_purchase_event_snippets( string $ad
399399
// Get the item info in the order
400400
$item_info = [];
401401
foreach ( $order->get_items() as $item_id => $item ) {
402-
$product_id = $item->get_product_id();
402+
$product_id = $item->get_variation_id() ?: $item->get_product_id();
403403
$product_name = $item->get_name();
404404
$quantity = $item->get_quantity();
405405
$price = $order->get_item_total( $item );
@@ -505,7 +505,7 @@ private function display_page_view_event_snippet(): void {
505505

506506
foreach ( WC()->cart->get_cart() as $cart_item ) {
507507
// gets the product id
508-
$id = $cart_item['product_id'];
508+
$id = ! empty( $cart_item['variation_id'] ) ? $cart_item['variation_id'] : $cart_item['product_id'];
509509

510510
// gets the product object
511511
$product = $cart_item['data'];

0 commit comments

Comments
 (0)