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, diff --git a/includes/class-wc-abstract-google-analytics-js.php b/includes/class-wc-abstract-google-analytics-js.php index 2c4fac5f..fac89125 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 ( $product->is_type( 'bundle' ) && is_callable( [ $product, 'get_bundle_price' ] ) ) { + $price = $product->get_bundle_price( 'min' ); + } + $formatted = array( 'id' => $product_id, 'name' => $product->get_title(),