Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static function maybe_add_newspack_notices() {
* @return string[] The notices.
*/
private static function get_notices() {
if ( ! function_exists( 'wcs_get_subscriptions' ) ) {
if ( ! function_exists( 'wcs_get_subscriptions' ) || ! function_exists( 'wc_get_product' ) ) {
return [];
}

Expand All @@ -134,7 +134,25 @@ private static function get_notices() {
continue;
}

$product = array_values( $subscription->get_items() )[0]->get_product();
$line_item = reset( $subscription->get_items() );
$product = wc_get_product( $line_item->get_product_id() );
// If the product has a parent, use the parent product.
if ( $product->get_parent_id() ) {
$product = wc_get_product( $product->get_parent_id() );
}
// If the product belongs to a grouped product, use the grouped product.
if ( class_exists( 'WC_Subscriptions_Product' ) && method_exists( 'WC_Subscriptions_Product', 'get_visible_grouped_parent_product_ids' ) ) {
$parent = \WC_Subscriptions_Product::get_visible_grouped_parent_product_ids( $product );
if ( ! empty( $parent ) ) {
$product = wc_get_product( reset( $parent ) );
}
}
// Check if there's another active subscription of the same grouped or variable product.
$active_subscriptions = WooCommerce_Subscriptions::get_user_subscription( $product );
if ( $active_subscriptions ) {
continue;
}

$is_donation = Donations::is_donation_product( $product->get_id() );

$link_attrs = [];
Expand Down