Title: $cart_contains_subscription is undefined
Last modified: January 6, 2025

---

# $cart_contains_subscription is undefined

 *  Resolved [falkemediawy](https://wordpress.org/support/users/falkemediawy/)
 * (@falkemediawy)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/cart_contains_subscription-is-undefined/)
 * Hi there, 
   since the last update to version 8.6.0 we receive an error on the 
   cart page. It says that in the file /plugins/woocommerce-payments/includes/class-
   wc-payments.php on line 1887 the variable $cart_contains_subscription isn’t defined.
   Well, yes, it isn’t defined if the if-condition above it is not executed (the
   variable is initialized inside the if). I fixed it by initializing it with “false”
   right below where $is_subscription is initialized (line 1879). Would be nice 
   if this issue is fixed in the next update!Cheers, Lisa

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Thread Starter [falkemediawy](https://wordpress.org/support/users/falkemediawy/)
 * (@falkemediawy)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/cart_contains_subscription-is-undefined/#post-18180933)
 * I kept the variable in place and only added a default value at the beginning 
   of the function:
 *     ```wp-block-code
       	/**	 * Load stripe site messaging script.	 *	 * @return void	 */	public static function load_stripe_bnpl_site_messaging() {		// The messaging element shall not be shown for subscription products.		// As we are not too deep into subscriptions API, we follow simplistic approach for now.		$is_subscription           = false;		$cart_contains_subscription = false; // this line is the new one :)		$are_subscriptions_enabled = class_exists( 'WC_Subscriptions' ) || class_exists( 'WC_Subscriptions_Core_Plugin' );		if ( $are_subscriptions_enabled ) {				global $product;				$is_subscription            = $product && WC_Subscriptions_Product::is_subscription( $product );				$cart_contains_subscription = is_cart() && WC_Subscriptions_Cart::cart_contains_subscription();		}		if ( ! $is_subscription && ! $cart_contains_subscription ) {			require_once __DIR__ . '/class-wc-payments-payment-method-messaging-element.php';			$stripe_site_messaging = new WC_Payments_Payment_Method_Messaging_Element( self::$account, self::$card_gateway );			echo wp_kses( $stripe_site_messaging->init() ?? '', 'post' );		}	}
       ```
   
    -  This reply was modified 1 year, 4 months ago by [falkemediawy](https://wordpress.org/support/users/falkemediawy/).
 *  [Zee](https://wordpress.org/support/users/doublezed2/)
 * (@doublezed2)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/cart_contains_subscription-is-undefined/#post-18184403)
 * Hello [falkemediawy](https://wordpress.org/support/users/falkemediawy/),
 * Thank you for contacting WooCommerce support.
 * I appreciate your time and effort in reporting this issue along with the solution.
   
   It is already being helpful for other users.
 * I will double-check this issue and notify the relevant team.
 * Have a great day!
 *  Plugin Support [Adam Heckler](https://wordpress.org/support/users/adamkheckler/)
 * (@adamkheckler)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/cart_contains_subscription-is-undefined/#post-18191762)
 * We have [a fix for this](https://github.com/Automattic/woocommerce-payments/pull/9893)
   going out in the next release. 🙂
 *  Thread Starter [falkemediawy](https://wordpress.org/support/users/falkemediawy/)
 * (@falkemediawy)
 * [1 year, 4 months ago](https://wordpress.org/support/topic/cart_contains_subscription-is-undefined/#post-18193935)
 * Thank you for the quick fix [@adamkheckler](https://wordpress.org/support/users/adamkheckler/)!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘$cart_contains_subscription is undefined’ is closed to new replies.

 * ![](https://ps.w.org/woocommerce-payments/assets/icon-256x256.png?rev=3234740)
 * [WooPayments: Integrated WooCommerce Payments](https://wordpress.org/plugins/woocommerce-payments/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/woocommerce-payments/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/woocommerce-payments/)
 * [Active Topics](https://wordpress.org/support/plugin/woocommerce-payments/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/woocommerce-payments/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/woocommerce-payments/reviews/)

 * 4 replies
 * 14 participants
 * Last reply from: [falkemediawy](https://wordpress.org/support/users/falkemediawy/)
 * Last activity: [1 year, 4 months ago](https://wordpress.org/support/topic/cart_contains_subscription-is-undefined/#post-18193935)
 * Status: resolved