@@ -110,7 +110,7 @@ public static function maybe_add_newspack_notices() {
110110 * @return string[] The notices.
111111 */
112112 private static function get_notices () {
113- if ( ! function_exists ( 'wcs_get_subscriptions ' ) ) {
113+ if ( ! function_exists ( 'wcs_get_subscriptions ' ) || ! function_exists ( ' wc_get_product ' ) ) {
114114 return [];
115115 }
116116
@@ -134,7 +134,25 @@ private static function get_notices() {
134134 continue ;
135135 }
136136
137- $ product = array_values ( $ subscription ->get_items () )[0 ]->get_product ();
137+ $ line_item = reset ( $ subscription ->get_items () );
138+ $ product = wc_get_product ( $ line_item ->get_product_id () );
139+ // If the product has a parent, use the parent product.
140+ if ( $ product ->get_parent_id () ) {
141+ $ product = wc_get_product ( $ product ->get_parent_id () );
142+ }
143+ // If the product belongs to a grouped product, use the grouped product.
144+ if ( class_exists ( 'WC_Subscriptions_Product ' ) && method_exists ( 'WC_Subscriptions_Product ' , 'get_visible_grouped_parent_product_ids ' ) ) {
145+ $ parent = \WC_Subscriptions_Product::get_visible_grouped_parent_product_ids ( $ product );
146+ if ( ! empty ( $ parent ) ) {
147+ $ product = wc_get_product ( reset ( $ parent ) );
148+ }
149+ }
150+ // Check if there's another active subscription of the same grouped or variable product.
151+ $ active_subscriptions = WooCommerce_Subscriptions::get_user_subscription ( $ product );
152+ if ( $ active_subscriptions ) {
153+ continue ;
154+ }
155+
138156 $ is_donation = Donations::is_donation_product ( $ product ->get_id () );
139157
140158 $ link_attrs = [];
0 commit comments