From 55ef826168fd8f3f7907b53d15f0e8f106e14c1a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Sun, 16 Jun 2024 20:18:21 +0200 Subject: [PATCH 1/3] Add dedicated integration with Product Bundles, Use `->get_bundle_price( 'min' );` instead of `->get_price()` for bundles. Fixes https://github.com/woocommerce/woocommerce-google-analytics-integration/issues/219 the simples way. --- includes/class-wc-abstract-google-analytics-js.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/includes/class-wc-abstract-google-analytics-js.php b/includes/class-wc-abstract-google-analytics-js.php index 2c4fac5f..2d8fe1a3 100644 --- a/includes/class-wc-abstract-google-analytics-js.php +++ b/includes/class-wc-abstract-google-analytics-js.php @@ -230,6 +230,13 @@ public function get_formatted_product( WC_Product $product, $variation_id = 0, $ } } + // Integration with Product Bundles. + // Get the minimum price, as `get_price` may return 0 if the product is a bundle and the price is potentially a range. + // Even a range containing a single value. + if ( class_exists( '\WC_Product_Bundle' ) && $product instanceof WC_Product_Bundle && is_callable( [ $product, 'get_bundle_price' ] ) ) { + $price = $product->get_bundle_price( 'min' ); + } + $formatted = array( 'id' => $product_id, 'name' => $product->get_title(), From 3061687fb204f06b20d21733da28ecee1028a198 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Tue, 18 Jun 2024 16:03:47 +0200 Subject: [PATCH 2/3] Simplify bundle price identification https://github.com/woocommerce/woocommerce-google-analytics-integration/pull/439#discussion_r1644397118 Co-authored-by: martynmjones <40762232+martynmjones@users.noreply.github.com> --- 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 2d8fe1a3..fac89125 100644 --- a/includes/class-wc-abstract-google-analytics-js.php +++ b/includes/class-wc-abstract-google-analytics-js.php @@ -233,7 +233,7 @@ public function get_formatted_product( WC_Product $product, $variation_id = 0, $ // Integration with Product Bundles. // Get the minimum price, as `get_price` may return 0 if the product is a bundle and the price is potentially a range. // Even a range containing a single value. - if ( class_exists( '\WC_Product_Bundle' ) && $product instanceof WC_Product_Bundle && is_callable( [ $product, 'get_bundle_price' ] ) ) { + if ( $product->is_type( 'bundle' ) && is_callable( [ $product, 'get_bundle_price' ] ) ) { $price = $product->get_bundle_price( 'min' ); } From 7860b3cdd46c2c6ec22326e97cfccf265ae8cf81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tomek=20Wytr=C4=99bowicz?= Date: Tue, 18 Jun 2024 21:04:31 +0200 Subject: [PATCH 3/3] Add support for bundled product price in Block handlers Address https://github.com/woocommerce/woocommerce-google-analytics-integration/pull/439#pullrequestreview-2125408349 --- assets/js/src/utils/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/assets/js/src/utils/index.js b/assets/js/src/utils/index.js index 789c209c..2aa222b2 100644 --- a/assets/js/src/utils/index.js +++ b/assets/js/src/utils/index.js @@ -21,7 +21,8 @@ export const getProductFieldObject = ( product, quantity ) => { ...getProductCategories( product ), quantity: product.quantity ?? quantity, price: formatPrice( - product.prices.price, + // Use line total for bundled products, if available. + product.totals?.line_total || product.prices.price, product.prices.currency_minor_unit ), ...variantData,