From ec9848a97acc33ec24dbe279b7707dcbe7b950fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Thu, 7 Mar 2024 13:42:35 +0100 Subject: [PATCH 1/2] Fix formatting product when variation has no attributes Address https://github.com/woocommerce/woocommerce-google-analytics-integration/issues/371 --- includes/class-wc-abstract-google-analytics-js.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/class-wc-abstract-google-analytics-js.php b/includes/class-wc-abstract-google-analytics-js.php index a71b6109..8543a86e 100644 --- a/includes/class-wc-abstract-google-analytics-js.php +++ b/includes/class-wc-abstract-google-analytics-js.php @@ -230,7 +230,7 @@ public function get_formatted_product( WC_Product $product, $variation = false ) $variation = $product->get_attributes(); } - if ( false !== $variation ) { + if ( false !== $variation && is_array( $variation ) ) { $formatted['variation'] = implode( ', ', array_map( From 9e094350582381200df990a37385e9e5dcef227e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Thu, 7 Mar 2024 18:19:21 +0100 Subject: [PATCH 2/2] Simplify the check for product variation, add a bit more elaborate code comment. --- includes/class-wc-abstract-google-analytics-js.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/class-wc-abstract-google-analytics-js.php b/includes/class-wc-abstract-google-analytics-js.php index 8543a86e..d73b4458 100644 --- a/includes/class-wc-abstract-google-analytics-js.php +++ b/includes/class-wc-abstract-google-analytics-js.php @@ -204,6 +204,7 @@ function ( $item ) { * * @param WC_Product $product The product to format. * @param array|bool $variation An array containing product variation attributes to include in the product data. + * For the "variation" type products, we'll use product->get_attributes. * * @return array */ @@ -230,7 +231,7 @@ public function get_formatted_product( WC_Product $product, $variation = false ) $variation = $product->get_attributes(); } - if ( false !== $variation && is_array( $variation ) ) { + if ( is_array( $variation ) ) { $formatted['variation'] = implode( ', ', array_map(